xref: /illumos-gate/usr/src/uts/common/io/bge/bge_kstats.c (revision 9b14cf1dc76dad8f2d9a74310e0a0200af96d217)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
562387023Sdduvall  * Common Development and Distribution License (the "License").
662387023Sdduvall  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
2162387023Sdduvall 
227c478bd9Sstevel@tonic-gate /*
235952d588Szh199473  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
29f724721bSzh199473 #include "bge_impl.h"
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #define	BGE_DBG		BGE_DBG_STATS	/* debug flag for this code	*/
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate  * Type of transceiver currently in use.  The IEEE 802.3 std aPhyType
357c478bd9Sstevel@tonic-gate  * enumerates the following set
367c478bd9Sstevel@tonic-gate  */
377c478bd9Sstevel@tonic-gate enum xcvr_type {
387c478bd9Sstevel@tonic-gate 	XCVR_TYPE_UNDEFINED = 0,    /* 0 = undefined, or not yet known */
397c478bd9Sstevel@tonic-gate 	XCVR_TYPE_NONE,		/* 1= MII present & nothing connected */
407c478bd9Sstevel@tonic-gate 	XCVR_TYPE_10BASE_T,		/* 2 = 10 Mbps copper */
417c478bd9Sstevel@tonic-gate 	XCVR_TYPE_100BASE_T4,	/* 3 = 10 Mbps copper */
427c478bd9Sstevel@tonic-gate 	XCVR_TYPE_100BASE_X,	/* 4 = 100 Mbps copper */
437c478bd9Sstevel@tonic-gate 	XCVR_TYPE_100BASE_T2,	/* 5 = 100 Mbps copper */
447c478bd9Sstevel@tonic-gate 	XCVR_TYPE_1000BASE_X,	/* 6 = 1000 Mbps SerDes */
457c478bd9Sstevel@tonic-gate 	XCVR_TYPE_1000BASE_T	/* 7 = 1000 Mbps copper */
467c478bd9Sstevel@tonic-gate };
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate /*
497c478bd9Sstevel@tonic-gate  * Local datatype for defining tables of (Offset, Name) pairs
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate typedef struct {
527c478bd9Sstevel@tonic-gate 	offset_t	index;
537c478bd9Sstevel@tonic-gate 	char		*name;
547c478bd9Sstevel@tonic-gate } bge_ksindex_t;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate /*
587c478bd9Sstevel@tonic-gate  * Table of Hardware-defined Statistics Block Offsets and Names
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate #define	KS_NAME(s)			{ KS_ ## s, #s }
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate static const bge_ksindex_t bge_statistics[] = {
637c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCInOctets),
647c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsFragments),
657c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCInUcastPkts),
667c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCInMulticastPkts),
677c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCInBroadcastPkts),
687c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsFCSErrors),
697c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsAlignmentErrors),
707c478bd9Sstevel@tonic-gate 	KS_NAME(xonPauseFramesReceived),
717c478bd9Sstevel@tonic-gate 	KS_NAME(xoffPauseFramesReceived),
727c478bd9Sstevel@tonic-gate 	KS_NAME(macControlFramesReceived),
737c478bd9Sstevel@tonic-gate 	KS_NAME(xoffStateEntered),
747c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsFrameTooLongs),
757c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsJabbers),
767c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsUndersizePkts),
777c478bd9Sstevel@tonic-gate 	KS_NAME(inRangeLengthError),
787c478bd9Sstevel@tonic-gate 	KS_NAME(outRangeLengthError),
797c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts64Octets),
807c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts65to127Octets),
817c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts128to255Octets),
827c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts256to511Octets),
837c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts512to1023Octets),
847c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts1024to1518Octets),
857c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts1519to2047Octets),
867c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts2048to4095Octets),
877c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts4096to8191Octets),
887c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts8192to9022Octets),
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCOutOctets),
917c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsCollisions),
927c478bd9Sstevel@tonic-gate 	KS_NAME(outXonSent),
937c478bd9Sstevel@tonic-gate 	KS_NAME(outXoffSent),
947c478bd9Sstevel@tonic-gate 	KS_NAME(flowControlDone),
957c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsInternalMacTransmitErrors),
967c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsSingleCollisionFrames),
977c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsMultipleCollisionFrames),
987c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsDeferredTransmissions),
997c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsExcessiveCollisions),
1007c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsLateCollisions),
1017c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided2Times),
1027c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided3Times),
1037c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided4Times),
1047c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided5Times),
1057c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided6Times),
1067c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided7Times),
1077c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided8Times),
1087c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided9Times),
1097c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided10Times),
1107c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided11Times),
1117c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided12Times),
1127c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided13Times),
1137c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided14Times),
1147c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided15Times),
1157c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCOutUcastPkts),
1167c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCOutMulticastPkts),
1177c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCOutBroadcastPkts),
1187c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsCarrierSenseErrors),
1197c478bd9Sstevel@tonic-gate 	KS_NAME(ifOutDiscards),
1207c478bd9Sstevel@tonic-gate 	KS_NAME(ifOutErrors),
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_1),
1237c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_2),
1247c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_3),
1257c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_4),
1267c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_5),
1277c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_6),
1287c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_7),
1297c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_8),
1307c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_9),
1317c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_10),
1327c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_11),
1337c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_12),
1347c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_13),
1357c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_14),
1367c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_15),
1377c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_16),
1387c478bd9Sstevel@tonic-gate 	KS_NAME(COSFramesDroppedDueToFilters),
1397c478bd9Sstevel@tonic-gate 	KS_NAME(nicDmaWriteQueueFull),
1407c478bd9Sstevel@tonic-gate 	KS_NAME(nicDmaWriteHighPriQueueFull),
1417c478bd9Sstevel@tonic-gate 	KS_NAME(nicNoMoreRxBDs),
1427c478bd9Sstevel@tonic-gate 	KS_NAME(ifInDiscards),
1437c478bd9Sstevel@tonic-gate 	KS_NAME(ifInErrors),
1447c478bd9Sstevel@tonic-gate 	KS_NAME(nicRecvThresholdHit),
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_1),
1477c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_2),
1487c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_3),
1497c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_4),
1507c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_5),
1517c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_6),
1527c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_7),
1537c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_8),
1547c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_9),
1557c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_10),
1567c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_11),
1577c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_12),
1587c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_13),
1597c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_14),
1607c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_15),
1617c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_16),
1627c478bd9Sstevel@tonic-gate 	KS_NAME(nicDmaReadQueueFull),
1637c478bd9Sstevel@tonic-gate 	KS_NAME(nicDmaReadHighPriQueueFull),
1647c478bd9Sstevel@tonic-gate 	KS_NAME(nicSendDataCompQueueFull),
1657c478bd9Sstevel@tonic-gate 	KS_NAME(nicRingSetSendProdIndex),
1667c478bd9Sstevel@tonic-gate 	KS_NAME(nicRingStatusUpdate),
1677c478bd9Sstevel@tonic-gate 	KS_NAME(nicInterrupts),
1687c478bd9Sstevel@tonic-gate 	KS_NAME(nicAvoidedInterrupts),
1697c478bd9Sstevel@tonic-gate 	KS_NAME(nicSendThresholdHit),
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	{ KS_STATS_SIZE, NULL }
1727c478bd9Sstevel@tonic-gate };
1737c478bd9Sstevel@tonic-gate 
1748eb6c4f9Sly149593 static const bge_ksindex_t bge_stat_val[] = {
1758eb6c4f9Sly149593 	KS_NAME(ifHCOutOctets),
1768eb6c4f9Sly149593 	KS_NAME(etherStatsCollisions),
1778eb6c4f9Sly149593 	KS_NAME(outXonSent),
1788eb6c4f9Sly149593 	KS_NAME(outXoffSent),
1798eb6c4f9Sly149593 	KS_NAME(dot3StatsInternalMacTransmitErrors),
1808eb6c4f9Sly149593 	KS_NAME(dot3StatsSingleCollisionFrames),
1818eb6c4f9Sly149593 	KS_NAME(dot3StatsMultipleCollisionFrames),
1828eb6c4f9Sly149593 	KS_NAME(dot3StatsDeferredTransmissions),
1838eb6c4f9Sly149593 	KS_NAME(dot3StatsExcessiveCollisions),
1848eb6c4f9Sly149593 	KS_NAME(dot3StatsLateCollisions),
1858eb6c4f9Sly149593 	KS_NAME(ifHCOutUcastPkts),
1868eb6c4f9Sly149593 	KS_NAME(ifHCOutMulticastPkts),
1878eb6c4f9Sly149593 	KS_NAME(ifHCOutBroadcastPkts),
1888eb6c4f9Sly149593 	KS_NAME(ifHCInOctets),
1898eb6c4f9Sly149593 	KS_NAME(etherStatsFragments),
1908eb6c4f9Sly149593 	KS_NAME(ifHCInUcastPkts),
1918eb6c4f9Sly149593 	KS_NAME(ifHCInMulticastPkts),
1928eb6c4f9Sly149593 	KS_NAME(ifHCInBroadcastPkts),
1938eb6c4f9Sly149593 	KS_NAME(dot3StatsFCSErrors),
1948eb6c4f9Sly149593 	KS_NAME(dot3StatsAlignmentErrors),
1958eb6c4f9Sly149593 	KS_NAME(xonPauseFramesReceived),
1968eb6c4f9Sly149593 	KS_NAME(xoffPauseFramesReceived),
1978eb6c4f9Sly149593 	KS_NAME(macControlFramesReceived),
1988eb6c4f9Sly149593 	KS_NAME(xoffStateEntered),
1998eb6c4f9Sly149593 	KS_NAME(dot3StatsFrameTooLongs),
2008eb6c4f9Sly149593 	KS_NAME(etherStatsJabbers),
2018eb6c4f9Sly149593 	KS_NAME(etherStatsUndersizePkts),
2028eb6c4f9Sly149593 
2038eb6c4f9Sly149593 	{ KS_STAT_REG_SIZE, NULL }
2048eb6c4f9Sly149593 };
2058eb6c4f9Sly149593 
2067c478bd9Sstevel@tonic-gate static int
2077c478bd9Sstevel@tonic-gate bge_statistics_update(kstat_t *ksp, int flag)
2087c478bd9Sstevel@tonic-gate {
2097c478bd9Sstevel@tonic-gate 	bge_t *bgep;
2107c478bd9Sstevel@tonic-gate 	bge_statistics_t *bstp;
211931dca7dSgs150176 	bge_statistics_reg_t *pstats;
2127c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
2137c478bd9Sstevel@tonic-gate 	const bge_ksindex_t *ksip;
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	if (flag != KSTAT_READ)
2167c478bd9Sstevel@tonic-gate 		return (EACCES);
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	bgep = ksp->ks_private;
2198eb6c4f9Sly149593 	if (bgep->chipid.statistic_type == BGE_STAT_BLK)
2207c478bd9Sstevel@tonic-gate 		bstp = DMA_VPTR(bgep->statistics);
2218eb6c4f9Sly149593 
2227c478bd9Sstevel@tonic-gate 	knp = ksp->ks_data;
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate 	/*
2257c478bd9Sstevel@tonic-gate 	 * Transfer the statistics values from the copy that the
2267c478bd9Sstevel@tonic-gate 	 * chip updates via DMA to the named-kstat structure.
2277c478bd9Sstevel@tonic-gate 	 *
2287c478bd9Sstevel@tonic-gate 	 * As above, we don't bother to sync or stop updates to the
2297c478bd9Sstevel@tonic-gate 	 * statistics, 'cos it doesn't really matter if they're a few
230256e438eSzh199473 	 * microseconds out of date or less than 100% consistent ...
2317c478bd9Sstevel@tonic-gate 	 */
2328eb6c4f9Sly149593 	if (bgep->chipid.statistic_type == BGE_STAT_BLK)
2337c478bd9Sstevel@tonic-gate 		for (ksip = bge_statistics; ksip->name != NULL; ++knp, ++ksip)
2347c478bd9Sstevel@tonic-gate 			knp->value.ui64 = bstp->a[ksip->index];
2358eb6c4f9Sly149593 	else {
236931dca7dSgs150176 		pstats = bgep->pstats;
237931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCOutOctets);
238931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->etherStatsCollisions);
239931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->outXonSent);
240931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->outXoffSent);
2418eb6c4f9Sly149593 		(knp++)->value.ui64 =
242931dca7dSgs150176 		    (uint64_t)(pstats->dot3StatsInternalMacTransmitErrors);
2438eb6c4f9Sly149593 		(knp++)->value.ui64 =
244931dca7dSgs150176 		    (uint64_t)(pstats->dot3StatsSingleCollisionFrames);
2458eb6c4f9Sly149593 		(knp++)->value.ui64 =
246931dca7dSgs150176 		    (uint64_t)(pstats->dot3StatsMultipleCollisionFrames);
2478eb6c4f9Sly149593 		(knp++)->value.ui64 =
248931dca7dSgs150176 		    (uint64_t)(pstats->dot3StatsDeferredTransmissions);
2498eb6c4f9Sly149593 		(knp++)->value.ui64 =
250931dca7dSgs150176 		    (uint64_t)(pstats->dot3StatsExcessiveCollisions);
2518eb6c4f9Sly149593 		(knp++)->value.ui64 =
252931dca7dSgs150176 		    (uint64_t)(pstats->dot3StatsLateCollisions);
253931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCOutUcastPkts);
254931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCOutMulticastPkts);
255931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCOutBroadcastPkts);
256931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCInOctets);
257931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->etherStatsFragments);
258931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCInUcastPkts);
259931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCInMulticastPkts);
260931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCInBroadcastPkts);
261931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->dot3StatsFCSErrors);
2628eb6c4f9Sly149593 		(knp++)->value.ui64 =
263931dca7dSgs150176 		    (uint64_t)(pstats->dot3StatsAlignmentErrors);
2648eb6c4f9Sly149593 		(knp++)->value.ui64 =
265931dca7dSgs150176 		    (uint64_t)(pstats->xonPauseFramesReceived);
2668eb6c4f9Sly149593 		(knp++)->value.ui64 =
267931dca7dSgs150176 		    (uint64_t)(pstats->xoffPauseFramesReceived);
2688eb6c4f9Sly149593 		(knp++)->value.ui64 =
269931dca7dSgs150176 		    (uint64_t)(pstats->macControlFramesReceived);
270931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->xoffStateEntered);
2718eb6c4f9Sly149593 		(knp++)->value.ui64 =
272931dca7dSgs150176 		    (uint64_t)(pstats->dot3StatsFrameTooLongs);
273931dca7dSgs150176 		(knp++)->value.ui64 = (uint64_t)(pstats->etherStatsJabbers);
2748eb6c4f9Sly149593 		(knp++)->value.ui64 =
275931dca7dSgs150176 		    (uint64_t)(pstats->etherStatsUndersizePkts);
2768eb6c4f9Sly149593 	}
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	return (0);
2797c478bd9Sstevel@tonic-gate }
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate static int
2827c478bd9Sstevel@tonic-gate bge_params_update(kstat_t *ksp, int flag)
2837c478bd9Sstevel@tonic-gate {
2847c478bd9Sstevel@tonic-gate 	bge_t *bgep;
2857c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
2867c478bd9Sstevel@tonic-gate 	int i;
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	if (flag != KSTAT_READ)
2897c478bd9Sstevel@tonic-gate 		return (EACCES);
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	bgep = ksp->ks_private;
2927c478bd9Sstevel@tonic-gate 	for (knp = ksp->ks_data, i = 0; i < PARAM_COUNT; ++knp, ++i)
2937c478bd9Sstevel@tonic-gate 		knp->value.ui64 = bgep->nd_params[i].ndp_val;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	return (0);
2967c478bd9Sstevel@tonic-gate }
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate static const bge_ksindex_t bge_chipid[] = {
2997c478bd9Sstevel@tonic-gate 	{ 0,				"asic_rev"		},
3007c478bd9Sstevel@tonic-gate 	{ 1,				"businfo"		},
3017c478bd9Sstevel@tonic-gate 	{ 2,				"command"		},
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	{ 3,				"vendor_id"		},
3047c478bd9Sstevel@tonic-gate 	{ 4,				"device_id"		},
3057c478bd9Sstevel@tonic-gate 	{ 5,				"subsystem_vendor_id"	},
3067c478bd9Sstevel@tonic-gate 	{ 6,				"subsystem_device_id"	},
3077c478bd9Sstevel@tonic-gate 	{ 7,				"revision_id"		},
3087c478bd9Sstevel@tonic-gate 	{ 8,				"cache_line_size"	},
3097c478bd9Sstevel@tonic-gate 	{ 9,				"latency_timer"		},
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	{ 10,				"flags"			},
3127c478bd9Sstevel@tonic-gate 	{ 11,				"chip_type"		},
3137c478bd9Sstevel@tonic-gate 	{ 12,				"mbuf_base"		},
3147c478bd9Sstevel@tonic-gate 	{ 13,				"mbuf_count"		},
3157c478bd9Sstevel@tonic-gate 	{ 14,				"hw_mac_addr"		},
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 	{ 15,				"&bus_type"		},
3187c478bd9Sstevel@tonic-gate 	{ 16,				"&bus_speed"		},
3197c478bd9Sstevel@tonic-gate 	{ 17,				"&bus_size"		},
3207c478bd9Sstevel@tonic-gate 	{ 18,				"&supported"		},
3217c478bd9Sstevel@tonic-gate 	{ 19,				"&interface"		},
3227c478bd9Sstevel@tonic-gate 
3237c478bd9Sstevel@tonic-gate 	{ -1,				NULL 			}
3247c478bd9Sstevel@tonic-gate };
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate static void
3277c478bd9Sstevel@tonic-gate bge_set_char_kstat(kstat_named_t *knp, const char *s)
3287c478bd9Sstevel@tonic-gate {
3297c478bd9Sstevel@tonic-gate 	(void) strncpy(knp->value.c, s, sizeof (knp->value.c));
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate static int
3337c478bd9Sstevel@tonic-gate bge_chipid_update(kstat_t *ksp, int flag)
3347c478bd9Sstevel@tonic-gate {
3357c478bd9Sstevel@tonic-gate 	bge_t *bgep;
3367c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
3377c478bd9Sstevel@tonic-gate 	uint64_t tmp;
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 	if (flag != KSTAT_READ)
3407c478bd9Sstevel@tonic-gate 		return (EACCES);
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	bgep = ksp->ks_private;
3437c478bd9Sstevel@tonic-gate 	knp = ksp->ks_data;
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.asic_rev;
3467c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.businfo;
3477c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.command;
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.vendor;
3507c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.device;
3517c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.subven;
3527c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.subdev;
3537c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.revision;
3547c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.clsize;
3557c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.latency;
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.flags;
3587c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.chip_label;
3597c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.mbuf_base;
3607c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.mbuf_length;
3617c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.hw_mac_addr;
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	/*
3647c478bd9Sstevel@tonic-gate 	 * Now we interpret some of the above into readable strings
3657c478bd9Sstevel@tonic-gate 	 */
3667c478bd9Sstevel@tonic-gate 	tmp = bgep->chipid.businfo;
3677c478bd9Sstevel@tonic-gate 	bge_set_char_kstat(knp++,
3687c478bd9Sstevel@tonic-gate 		tmp & PCISTATE_BUS_IS_PCI ? "PCI" : "PCI-X");
3697c478bd9Sstevel@tonic-gate 	bge_set_char_kstat(knp++,
3707c478bd9Sstevel@tonic-gate 		tmp & PCISTATE_BUS_IS_FAST ? "fast" : "normal");
3717c478bd9Sstevel@tonic-gate 	bge_set_char_kstat(knp++,
3727c478bd9Sstevel@tonic-gate 		tmp & PCISTATE_BUS_IS_32_BIT ? "32 bit" : "64 bit");
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 	tmp = bgep->chipid.flags;
3757c478bd9Sstevel@tonic-gate 	bge_set_char_kstat(knp++,
3767c478bd9Sstevel@tonic-gate 		tmp & CHIP_FLAG_SUPPORTED ? "yes" : "no");
3777c478bd9Sstevel@tonic-gate 	bge_set_char_kstat(knp++,
3787c478bd9Sstevel@tonic-gate 		tmp & CHIP_FLAG_SERDES ? "serdes" : "copper");
3797c478bd9Sstevel@tonic-gate 
3807c478bd9Sstevel@tonic-gate 	return (0);
3817c478bd9Sstevel@tonic-gate }
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate static const bge_ksindex_t bge_driverinfo[] = {
3847c478bd9Sstevel@tonic-gate 	{ 0,				"rx_buff_addr"		},
3857c478bd9Sstevel@tonic-gate 	{ 1,				"tx_buff_addr"		},
3867c478bd9Sstevel@tonic-gate 	{ 2,				"rx_desc_addr"		},
3877c478bd9Sstevel@tonic-gate 	{ 3,				"tx_desc_addr"		},
3887c478bd9Sstevel@tonic-gate 
3897c478bd9Sstevel@tonic-gate 	{ 4,				"tx_desc_free"		},
390931dca7dSgs150176 	{ 5,				"tx_array"		},
391931dca7dSgs150176 	{ 6,				"tc_next"		},
392931dca7dSgs150176 	{ 7,				"tx_next"		},
393931dca7dSgs150176 	{ 8,				"txfill_next"		},
394931dca7dSgs150176 	{ 9,				"txpkt_next"		},
395931dca7dSgs150176 	{ 10,				"tx_bufs"		},
396931dca7dSgs150176 	{ 11,				"tx_flow"		},
397931dca7dSgs150176 	{ 12,				"tx_resched_needed"	},
398931dca7dSgs150176 	{ 13,				"tx_resched"		},
399931dca7dSgs150176 	{ 14,				"tx_nobuf"		},
400931dca7dSgs150176 	{ 15,				"tx_nobd"		},
401931dca7dSgs150176 	{ 16,				"tx_block"		},
402931dca7dSgs150176 	{ 17,				"tx_alloc_fail"		},
4037c478bd9Sstevel@tonic-gate 
404931dca7dSgs150176 	{ 18,				"watchdog"		},
405931dca7dSgs150176 	{ 19,				"chip_resets"		},
406931dca7dSgs150176 	{ 20,				"dma_misses"		},
4075952d588Szh199473 	{ 21,				"update_misses"		},
4087c478bd9Sstevel@tonic-gate 
4095952d588Szh199473 	{ 22,				"misc_host_config"	},
4105952d588Szh199473 	{ 23,				"dma_rw_control"	},
4115952d588Szh199473 	{ 24,				"pci_bus_info"		},
412931dca7dSgs150176 
4135952d588Szh199473 	{ 25,				"buff_mgr_status"	},
4145952d588Szh199473 	{ 26,				"rcv_init_status"	},
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate 	{ -1,				NULL 			}
4177c478bd9Sstevel@tonic-gate };
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate static int
4207c478bd9Sstevel@tonic-gate bge_driverinfo_update(kstat_t *ksp, int flag)
4217c478bd9Sstevel@tonic-gate {
4227c478bd9Sstevel@tonic-gate 	bge_t *bgep;
4237c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
4247c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t handle;
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate 	if (flag != KSTAT_READ)
4277c478bd9Sstevel@tonic-gate 		return (EACCES);
4287c478bd9Sstevel@tonic-gate 
4297c478bd9Sstevel@tonic-gate 	bgep = ksp->ks_private;
43000d0963fSdilpreet 	if (bgep->bge_chip_state == BGE_CHIP_FAULT)
43100d0963fSdilpreet 		return (EIO);
43200d0963fSdilpreet 
4337c478bd9Sstevel@tonic-gate 	knp = ksp->ks_data;
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->rx_buff[0].cookie.dmac_laddress;
4367c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->tx_buff[0].cookie.dmac_laddress;
4377c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->rx_desc[0].cookie.dmac_laddress;
4387c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->tx_desc.cookie.dmac_laddress;
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->send[0].tx_free;
441931dca7dSgs150176 	(knp++)->value.ui64 = bgep->send[0].tx_array;
442931dca7dSgs150176 	(knp++)->value.ui64 = bgep->send[0].tc_next;
443931dca7dSgs150176 	(knp++)->value.ui64 = bgep->send[0].tx_next;
444931dca7dSgs150176 	(knp++)->value.ui64 = bgep->send[0].txfill_next;
445931dca7dSgs150176 	(knp++)->value.ui64 = bgep->send[0].txpkt_next;
446931dca7dSgs150176 	(knp++)->value.ui64 = bgep->send[0].txbuf_pop_queue->count +
447931dca7dSgs150176 	    bgep->send[0].txbuf_push_queue->count;
448931dca7dSgs150176 	(knp++)->value.ui64 = bgep->send[0].tx_flow;
449931dca7dSgs150176 	(knp++)->value.ui64 = bgep->tx_resched_needed;
450931dca7dSgs150176 	(knp++)->value.ui64 = bgep->tx_resched;
451931dca7dSgs150176 	(knp++)->value.ui64 = bgep->send[0].tx_nobuf;
452931dca7dSgs150176 	(knp++)->value.ui64 = bgep->send[0].tx_nobd;
453931dca7dSgs150176 	(knp++)->value.ui64 = bgep->send[0].tx_block;
454931dca7dSgs150176 	(knp++)->value.ui64 = bgep->send[0].tx_alloc_fail;
455931dca7dSgs150176 
4567c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->watchdog;
4577c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chip_resets;
4587c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->missed_dmas;
4595952d588Szh199473 	(knp++)->value.ui64 = bgep->missed_updates;
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	/*
4627c478bd9Sstevel@tonic-gate 	 * Hold the mutex while accessing the chip registers
4637c478bd9Sstevel@tonic-gate 	 * just in case the factotum is trying to reset it!
4647c478bd9Sstevel@tonic-gate 	 */
4657c478bd9Sstevel@tonic-gate 	handle = bgep->cfg_handle;
4667c478bd9Sstevel@tonic-gate 	mutex_enter(bgep->genlock);
4677c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = pci_config_get32(handle, PCI_CONF_BGE_MHCR);
4687c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = pci_config_get32(handle, PCI_CONF_BGE_PDRWCR);
4697c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = pci_config_get32(handle, PCI_CONF_BGE_PCISTATE);
47000d0963fSdilpreet 	if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) {
47100d0963fSdilpreet 		ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED);
47200d0963fSdilpreet 		mutex_exit(bgep->genlock);
47300d0963fSdilpreet 		return (EIO);
47400d0963fSdilpreet 	}
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bge_reg_get32(bgep, BUFFER_MANAGER_STATUS_REG);
4777c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bge_reg_get32(bgep, RCV_INITIATOR_STATUS_REG);
47800d0963fSdilpreet 	if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) {
47900d0963fSdilpreet 		ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED);
48000d0963fSdilpreet 		mutex_exit(bgep->genlock);
48100d0963fSdilpreet 		return (EIO);
48200d0963fSdilpreet 	}
4837c478bd9Sstevel@tonic-gate 	mutex_exit(bgep->genlock);
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 	return (0);
4867c478bd9Sstevel@tonic-gate }
4877c478bd9Sstevel@tonic-gate 
4887c478bd9Sstevel@tonic-gate static const bge_ksindex_t bge_mii_kstats[] = {
4897c478bd9Sstevel@tonic-gate 	{ 0,				"%xcvr_addr"		},
4907c478bd9Sstevel@tonic-gate 	{ 1,				"%xcvr_id"		},
4917c478bd9Sstevel@tonic-gate 	{ 2,				"%xcvr_inuse"		},
4927c478bd9Sstevel@tonic-gate 
4937c478bd9Sstevel@tonic-gate 	{ 3,				"%cap_1000fdx"		},
4947c478bd9Sstevel@tonic-gate 	{ 4,				"%cap_1000hdx"		},
4957c478bd9Sstevel@tonic-gate 	{ 5,				"%cap_100fdx"		},
4967c478bd9Sstevel@tonic-gate 	{ 6,				"%cap_100hdx"		},
4977c478bd9Sstevel@tonic-gate 	{ 7,				"%cap_10fdx"		},
4987c478bd9Sstevel@tonic-gate 	{ 8,				"%cap_10hdx"		},
4997c478bd9Sstevel@tonic-gate 	{ 9,				"%cap_asmpause"		},
5007c478bd9Sstevel@tonic-gate 	{ 10,				"%cap_pause"		},
5017c478bd9Sstevel@tonic-gate 	{ 11,				"%cap_rem_fault"	},
5027c478bd9Sstevel@tonic-gate 	{ 12,				"%cap_autoneg"		},
5037c478bd9Sstevel@tonic-gate 
5047c478bd9Sstevel@tonic-gate 	{ 13,				"%adv_cap_1000fdx"	},
5057c478bd9Sstevel@tonic-gate 	{ 14,				"%adv_cap_1000hdx"	},
5067c478bd9Sstevel@tonic-gate 	{ 15,				"%adv_cap_100fdx"	},
5077c478bd9Sstevel@tonic-gate 	{ 16,				"%adv_cap_100hdx"	},
5087c478bd9Sstevel@tonic-gate 	{ 17,				"%adv_cap_10fdx"	},
5097c478bd9Sstevel@tonic-gate 	{ 18,				"%adv_cap_10hdx"	},
5107c478bd9Sstevel@tonic-gate 	{ 19,				"%adv_cap_asmpause"	},
5117c478bd9Sstevel@tonic-gate 	{ 20,				"%adv_cap_pause"	},
5127c478bd9Sstevel@tonic-gate 	{ 21,				"%adv_rem_fault"	},
5137c478bd9Sstevel@tonic-gate 	{ 22,				"%adv_cap_autoneg"	},
5147c478bd9Sstevel@tonic-gate 
5157c478bd9Sstevel@tonic-gate 	{ 23,				"%lp_cap_1000fdx"	},
5167c478bd9Sstevel@tonic-gate 	{ 24,				"%lp_cap_1000hdx"	},
5177c478bd9Sstevel@tonic-gate 	{ 25,				"%lp_cap_100fdx"	},
5187c478bd9Sstevel@tonic-gate 	{ 26,				"%lp_cap_100hdx"	},
5197c478bd9Sstevel@tonic-gate 	{ 27,				"%lp_cap_10fdx"		},
5207c478bd9Sstevel@tonic-gate 	{ 28,				"%lp_cap_10hdx"		},
5217c478bd9Sstevel@tonic-gate 	{ 29,				"%lp_cap_asmpause"	},
5227c478bd9Sstevel@tonic-gate 	{ 30,				"%lp_cap_pause"		},
5237c478bd9Sstevel@tonic-gate 	{ 31,				"%lp_rem_fault"		},
5247c478bd9Sstevel@tonic-gate 	{ 32,				"%lp_cap_autoneg"	},
5257c478bd9Sstevel@tonic-gate 
5267c478bd9Sstevel@tonic-gate 	{ 33,				"%link_asmpause"	},
5277c478bd9Sstevel@tonic-gate 	{ 34,				"%link_pause"		},
5287c478bd9Sstevel@tonic-gate 	{ 35,				"%link_duplex"		},
5297c478bd9Sstevel@tonic-gate 	{ 36,				"%link_up"		},
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 	{ -1,				NULL 			}
5327c478bd9Sstevel@tonic-gate };
5337c478bd9Sstevel@tonic-gate 
5347c478bd9Sstevel@tonic-gate /*
5357c478bd9Sstevel@tonic-gate  * Derive and publish the standard "mii" kstats.
5367c478bd9Sstevel@tonic-gate  *
5377c478bd9Sstevel@tonic-gate  * The information required is somewhat scattered: some is already held
5387c478bd9Sstevel@tonic-gate  * in driver softstate, some is available in the MII registers, and some
5397c478bd9Sstevel@tonic-gate  * has to be computed from combinations of both ...
5407c478bd9Sstevel@tonic-gate  */
5417c478bd9Sstevel@tonic-gate static int
5427c478bd9Sstevel@tonic-gate bge_mii_update(kstat_t *ksp, int flag)
5437c478bd9Sstevel@tonic-gate {
5447c478bd9Sstevel@tonic-gate 	bge_t *bgep;
5457c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
5467c478bd9Sstevel@tonic-gate 	uint16_t anlpar;
5477c478bd9Sstevel@tonic-gate 	uint16_t anar;
5487c478bd9Sstevel@tonic-gate 	uint32_t xcvr_id;
5497c478bd9Sstevel@tonic-gate 	uint32_t xcvr_inuse;
5507c478bd9Sstevel@tonic-gate 	boolean_t asym_pause;
5517c478bd9Sstevel@tonic-gate 
5527c478bd9Sstevel@tonic-gate 	if (flag != KSTAT_READ)
5537c478bd9Sstevel@tonic-gate 		return (EACCES);
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate 	bgep = ksp->ks_private;
55600d0963fSdilpreet 	if (bgep->bge_chip_state == BGE_CHIP_FAULT)
55700d0963fSdilpreet 		return (EIO);
55800d0963fSdilpreet 
5597c478bd9Sstevel@tonic-gate 	knp = ksp->ks_data;
5607c478bd9Sstevel@tonic-gate 
5617c478bd9Sstevel@tonic-gate 	/*
5627c478bd9Sstevel@tonic-gate 	 * Read all the relevant PHY registers
5637c478bd9Sstevel@tonic-gate 	 */
5647c478bd9Sstevel@tonic-gate 	mutex_enter(bgep->genlock);
5657c478bd9Sstevel@tonic-gate 	anlpar = bge_mii_get16(bgep, MII_AN_LPABLE);
5667c478bd9Sstevel@tonic-gate 	anar = bge_mii_get16(bgep, MII_AN_ADVERT);
5677c478bd9Sstevel@tonic-gate 
5687c478bd9Sstevel@tonic-gate 	/*
5697c478bd9Sstevel@tonic-gate 	 * Derive PHY characterisation parameters
5707c478bd9Sstevel@tonic-gate 	 */
5717c478bd9Sstevel@tonic-gate 	xcvr_id = bge_mii_get16(bgep, MII_PHYIDH);
5727c478bd9Sstevel@tonic-gate 	xcvr_id <<= 16;
5737c478bd9Sstevel@tonic-gate 	xcvr_id |= bge_mii_get16(bgep, MII_PHYIDL);
57400d0963fSdilpreet 	if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) {
57500d0963fSdilpreet 		ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED);
57600d0963fSdilpreet 		mutex_exit(bgep->genlock);
57700d0963fSdilpreet 		return (EIO);
57800d0963fSdilpreet 	}
5797c478bd9Sstevel@tonic-gate 	mutex_exit(bgep->genlock);
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate 	switch (bgep->param_link_speed) {
5827c478bd9Sstevel@tonic-gate 	case 1000:
5837c478bd9Sstevel@tonic-gate 		if (bgep->chipid.flags & CHIP_FLAG_SERDES)
5847c478bd9Sstevel@tonic-gate 			xcvr_inuse = XCVR_TYPE_1000BASE_X;
5857c478bd9Sstevel@tonic-gate 		else
5867c478bd9Sstevel@tonic-gate 			xcvr_inuse = XCVR_TYPE_1000BASE_T;
5877c478bd9Sstevel@tonic-gate 		break;
5887c478bd9Sstevel@tonic-gate 
5897c478bd9Sstevel@tonic-gate 	case 100:
5907c478bd9Sstevel@tonic-gate 		xcvr_inuse = XCVR_TYPE_100BASE_X;
5917c478bd9Sstevel@tonic-gate 		break;
5927c478bd9Sstevel@tonic-gate 
5937c478bd9Sstevel@tonic-gate 	case 10:
5947c478bd9Sstevel@tonic-gate 		xcvr_inuse = XCVR_TYPE_10BASE_T;
5957c478bd9Sstevel@tonic-gate 		break;
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate 	default:
5987c478bd9Sstevel@tonic-gate 		xcvr_inuse = XCVR_TYPE_UNDEFINED;
5997c478bd9Sstevel@tonic-gate 		break;
6007c478bd9Sstevel@tonic-gate 	}
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate 	/*
6037c478bd9Sstevel@tonic-gate 	 * Other miscellaneous transformations ...
6047c478bd9Sstevel@tonic-gate 	 */
6057c478bd9Sstevel@tonic-gate 	asym_pause = bgep->param_link_rx_pause != bgep->param_link_tx_pause;
6067c478bd9Sstevel@tonic-gate 
6077c478bd9Sstevel@tonic-gate 	/*
6087c478bd9Sstevel@tonic-gate 	 * All required values are now available; assign them to the
6097c478bd9Sstevel@tonic-gate 	 * actual kstats, in the sequence defined by the table above.
6107c478bd9Sstevel@tonic-gate 	 */
6117c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->phy_mii_addr;
6127c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = xcvr_id;
6137c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = xcvr_inuse;
6147c478bd9Sstevel@tonic-gate 
6157c478bd9Sstevel@tonic-gate 	/*
6167c478bd9Sstevel@tonic-gate 	 * Our capabilities
6177c478bd9Sstevel@tonic-gate 	 */
6187c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->nd_params[PARAM_1000FDX_CAP].ndp_val;
6197c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->nd_params[PARAM_1000HDX_CAP].ndp_val;
6207c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->nd_params[PARAM_100FDX_CAP].ndp_val;
6217c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->nd_params[PARAM_100HDX_CAP].ndp_val;
6227c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->nd_params[PARAM_10FDX_CAP].ndp_val;
6237c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->nd_params[PARAM_10HDX_CAP].ndp_val;
6247c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->nd_params[PARAM_ASYM_PAUSE_CAP].ndp_val;
6257c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->nd_params[PARAM_PAUSE_CAP].ndp_val;
6267c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = B_TRUE;
6277c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->nd_params[PARAM_AUTONEG_CAP].ndp_val;
6287c478bd9Sstevel@tonic-gate 
6297c478bd9Sstevel@tonic-gate 	/*
6307c478bd9Sstevel@tonic-gate 	 * Our *advertised* capabilities
6317c478bd9Sstevel@tonic-gate 	 */
6327c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_adv_1000fdx;
6337c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_adv_1000hdx;
6347c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_adv_100fdx;
6357c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_adv_100hdx;
6367c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_adv_10fdx;
6377c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_adv_10hdx;
6387c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_adv_asym_pause;
6397c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_adv_pause;
6407c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = (anar & MII_AN_ADVERT_REMFAULT) ? 1 : 0;
6417c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_adv_autoneg;
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate 	/*
6447c478bd9Sstevel@tonic-gate 	 * Link Partner's advertised capabilities
6457c478bd9Sstevel@tonic-gate 	 */
6467c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_lp_1000fdx;
6477c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_lp_1000hdx;
6487c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_lp_100fdx;
6497c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_lp_100hdx;
6507c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_lp_10fdx;
6517c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_lp_10hdx;
6527c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_lp_asym_pause;
6537c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_lp_pause;
6547c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = (anlpar & MII_AN_ADVERT_REMFAULT) ? 1 : 0;
6557c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_lp_autoneg;
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate 	/*
6587c478bd9Sstevel@tonic-gate 	 * Current operating modes
6597c478bd9Sstevel@tonic-gate 	 */
6607c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = asym_pause;
6617c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_link_rx_pause;
6627c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_link_duplex;
6637c478bd9Sstevel@tonic-gate 	(knp++)->value.ui32 = bgep->param_link_up;
6647c478bd9Sstevel@tonic-gate 
6657c478bd9Sstevel@tonic-gate 	return (0);
6667c478bd9Sstevel@tonic-gate }
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate static const bge_ksindex_t bge_serdes[] = {
6697c478bd9Sstevel@tonic-gate 	{ 0,				"serdes_status"		},
6707c478bd9Sstevel@tonic-gate 	{ 1,				"serdes_advert"		},
6717c478bd9Sstevel@tonic-gate 	{ 2,				"serdes_lpadv"		},
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate 	{ -1,				NULL }
6747c478bd9Sstevel@tonic-gate };
6757c478bd9Sstevel@tonic-gate 
6767c478bd9Sstevel@tonic-gate static int
6777c478bd9Sstevel@tonic-gate bge_serdes_update(kstat_t *ksp, int flag)
6787c478bd9Sstevel@tonic-gate {
6797c478bd9Sstevel@tonic-gate 	bge_t *bgep;
6807c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate 	if (flag != KSTAT_READ)
6837c478bd9Sstevel@tonic-gate 		return (EACCES);
6847c478bd9Sstevel@tonic-gate 
6857c478bd9Sstevel@tonic-gate 	bgep = ksp->ks_private;
6867c478bd9Sstevel@tonic-gate 	knp = ksp->ks_data;
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->serdes_status;
6897c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->serdes_advert;
6907c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->serdes_lpadv;
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 	return (0);
6937c478bd9Sstevel@tonic-gate }
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate static const bge_ksindex_t bge_phydata[] = {
6967c478bd9Sstevel@tonic-gate 	{ MII_CONTROL,			"mii_control"		},
6977c478bd9Sstevel@tonic-gate 	{ MII_STATUS,			"mii_status"		},
6987c478bd9Sstevel@tonic-gate 	{ MII_PHYIDH,			"phy_identifier"	},
6997c478bd9Sstevel@tonic-gate 	{ MII_AN_ADVERT,		"an_advert"		},
7007c478bd9Sstevel@tonic-gate 	{ MII_AN_LPABLE,		"an_lp_ability"		},
7017c478bd9Sstevel@tonic-gate 	{ MII_AN_EXPANSION,		"an_expansion"		},
7027c478bd9Sstevel@tonic-gate 	{ MII_AN_LPNXTPG,		"an_lp_nextpage"	},
7037c478bd9Sstevel@tonic-gate 	{ MII_1000BASE_T_CONTROL,	"gbit_control"		},
7047c478bd9Sstevel@tonic-gate 	{ MII_1000BASE_T_STATUS,	"gbit_status"		},
7057c478bd9Sstevel@tonic-gate 	{ MII_IEEE_EXT_STATUS,		"ieee_ext_status"	},
7067c478bd9Sstevel@tonic-gate 	{ MII_EXT_CONTROL,		"phy_ext_control"	},
7077c478bd9Sstevel@tonic-gate 	{ MII_EXT_STATUS,		"phy_ext_status"	},
7087c478bd9Sstevel@tonic-gate 	{ MII_RCV_ERR_COUNT,		"receive_error_count"	},
7097c478bd9Sstevel@tonic-gate 	{ MII_FALSE_CARR_COUNT,		"false_carrier_count"	},
7107c478bd9Sstevel@tonic-gate 	{ MII_RCV_NOT_OK_COUNT,		"receiver_not_ok_count"	},
7117c478bd9Sstevel@tonic-gate 	{ MII_AUX_CONTROL,		"aux_control"		},
7127c478bd9Sstevel@tonic-gate 	{ MII_AUX_STATUS,		"aux_status"		},
7137c478bd9Sstevel@tonic-gate 	{ MII_INTR_STATUS,		"intr_status"		},
7147c478bd9Sstevel@tonic-gate 	{ MII_INTR_MASK,		"intr_mask"		},
7157c478bd9Sstevel@tonic-gate 	{ MII_HCD_STATUS,		"hcd_status"		},
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate 	{ -1,				NULL }
7187c478bd9Sstevel@tonic-gate };
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate static int
7217c478bd9Sstevel@tonic-gate bge_phydata_update(kstat_t *ksp, int flag)
7227c478bd9Sstevel@tonic-gate {
7237c478bd9Sstevel@tonic-gate 	bge_t *bgep;
7247c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
7257c478bd9Sstevel@tonic-gate 	const bge_ksindex_t *ksip;
7267c478bd9Sstevel@tonic-gate 
7277c478bd9Sstevel@tonic-gate 	if (flag != KSTAT_READ)
7287c478bd9Sstevel@tonic-gate 		return (EACCES);
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate 	bgep = ksp->ks_private;
73100d0963fSdilpreet 	if (bgep->bge_chip_state == BGE_CHIP_FAULT)
73200d0963fSdilpreet 		return (EIO);
73300d0963fSdilpreet 
7347c478bd9Sstevel@tonic-gate 	knp = ksp->ks_data;
7357c478bd9Sstevel@tonic-gate 
7367c478bd9Sstevel@tonic-gate 	/*
7377c478bd9Sstevel@tonic-gate 	 * Read the PHY registers & update the kstats ...
7387c478bd9Sstevel@tonic-gate 	 *
7397c478bd9Sstevel@tonic-gate 	 * We need to hold the mutex while performing MII reads, but
7407c478bd9Sstevel@tonic-gate 	 * we don't want to hold it across the entire sequence of reads.
7417c478bd9Sstevel@tonic-gate 	 * So we grab and release it on each iteration, 'cos it doesn't
7427c478bd9Sstevel@tonic-gate 	 * really matter if the kstats are less than 100% consistent ...
7437c478bd9Sstevel@tonic-gate 	 */
7447c478bd9Sstevel@tonic-gate 	for (ksip = bge_phydata; ksip->name != NULL; ++knp, ++ksip) {
7457c478bd9Sstevel@tonic-gate 		mutex_enter(bgep->genlock);
7467c478bd9Sstevel@tonic-gate 		switch (ksip->index) {
7477c478bd9Sstevel@tonic-gate 		case MII_STATUS:
7487c478bd9Sstevel@tonic-gate 			knp->value.ui64 = bgep->phy_gen_status;
7497c478bd9Sstevel@tonic-gate 			break;
7507c478bd9Sstevel@tonic-gate 
7517c478bd9Sstevel@tonic-gate 		case MII_PHYIDH:
7527c478bd9Sstevel@tonic-gate 			knp->value.ui64 = bge_mii_get16(bgep, MII_PHYIDH);
7537c478bd9Sstevel@tonic-gate 			knp->value.ui64 <<= 16;
7547c478bd9Sstevel@tonic-gate 			knp->value.ui64 |= bge_mii_get16(bgep, MII_PHYIDL);
7557c478bd9Sstevel@tonic-gate 			break;
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate 		default:
7587c478bd9Sstevel@tonic-gate 			knp->value.ui64 = bge_mii_get16(bgep, ksip->index);
7597c478bd9Sstevel@tonic-gate 			break;
7607c478bd9Sstevel@tonic-gate 		}
76100d0963fSdilpreet 		if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) {
76200d0963fSdilpreet 			ddi_fm_service_impact(bgep->devinfo,
76300d0963fSdilpreet 			    DDI_SERVICE_DEGRADED);
76400d0963fSdilpreet 			mutex_exit(bgep->genlock);
76500d0963fSdilpreet 			return (EIO);
76600d0963fSdilpreet 		}
7677c478bd9Sstevel@tonic-gate 		mutex_exit(bgep->genlock);
7687c478bd9Sstevel@tonic-gate 	}
7697c478bd9Sstevel@tonic-gate 
7707c478bd9Sstevel@tonic-gate 	return (0);
7717c478bd9Sstevel@tonic-gate }
7727c478bd9Sstevel@tonic-gate 
7737c478bd9Sstevel@tonic-gate static kstat_t *
7747c478bd9Sstevel@tonic-gate bge_setup_named_kstat(bge_t *bgep, int instance, char *name,
7757c478bd9Sstevel@tonic-gate 	const bge_ksindex_t *ksip, size_t size, int (*update)(kstat_t *, int))
7767c478bd9Sstevel@tonic-gate {
7777c478bd9Sstevel@tonic-gate 	kstat_t *ksp;
7787c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
7797c478bd9Sstevel@tonic-gate 	char *np;
7807c478bd9Sstevel@tonic-gate 	int type;
7817c478bd9Sstevel@tonic-gate 
7827c478bd9Sstevel@tonic-gate 	size /= sizeof (bge_ksindex_t);
7837c478bd9Sstevel@tonic-gate 	ksp = kstat_create(BGE_DRIVER_NAME, instance, name, "net",
7847c478bd9Sstevel@tonic-gate 		KSTAT_TYPE_NAMED, size-1, KSTAT_FLAG_PERSISTENT);
7857c478bd9Sstevel@tonic-gate 	if (ksp == NULL)
7867c478bd9Sstevel@tonic-gate 		return (NULL);
7877c478bd9Sstevel@tonic-gate 
7887c478bd9Sstevel@tonic-gate 	ksp->ks_private = bgep;
7897c478bd9Sstevel@tonic-gate 	ksp->ks_update = update;
7907c478bd9Sstevel@tonic-gate 	for (knp = ksp->ks_data; (np = ksip->name) != NULL; ++knp, ++ksip) {
7917c478bd9Sstevel@tonic-gate 		switch (*np) {
7927c478bd9Sstevel@tonic-gate 		default:
7937c478bd9Sstevel@tonic-gate 			type = KSTAT_DATA_UINT64;
7947c478bd9Sstevel@tonic-gate 			break;
7957c478bd9Sstevel@tonic-gate 		case '%':
7967c478bd9Sstevel@tonic-gate 			np += 1;
7977c478bd9Sstevel@tonic-gate 			type = KSTAT_DATA_UINT32;
7987c478bd9Sstevel@tonic-gate 			break;
7997c478bd9Sstevel@tonic-gate 		case '$':
8007c478bd9Sstevel@tonic-gate 			np += 1;
8017c478bd9Sstevel@tonic-gate 			type = KSTAT_DATA_STRING;
8027c478bd9Sstevel@tonic-gate 			break;
8037c478bd9Sstevel@tonic-gate 		case '&':
8047c478bd9Sstevel@tonic-gate 			np += 1;
8057c478bd9Sstevel@tonic-gate 			type = KSTAT_DATA_CHAR;
8067c478bd9Sstevel@tonic-gate 			break;
8077c478bd9Sstevel@tonic-gate 		}
8087c478bd9Sstevel@tonic-gate 		kstat_named_init(knp, np, type);
8097c478bd9Sstevel@tonic-gate 	}
8107c478bd9Sstevel@tonic-gate 	kstat_install(ksp);
8117c478bd9Sstevel@tonic-gate 
8127c478bd9Sstevel@tonic-gate 	return (ksp);
8137c478bd9Sstevel@tonic-gate }
8147c478bd9Sstevel@tonic-gate 
8157c478bd9Sstevel@tonic-gate /*
8167c478bd9Sstevel@tonic-gate  * Create kstats corresponding to NDD parameters
8177c478bd9Sstevel@tonic-gate  */
8187c478bd9Sstevel@tonic-gate static kstat_t *
8197c478bd9Sstevel@tonic-gate bge_setup_params_kstat(bge_t *bgep, int instance, char *name,
8207c478bd9Sstevel@tonic-gate 	int (*update)(kstat_t *, int))
8217c478bd9Sstevel@tonic-gate {
8227c478bd9Sstevel@tonic-gate 	kstat_t *ksp;
8237c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
8247c478bd9Sstevel@tonic-gate 	int i;
8257c478bd9Sstevel@tonic-gate 
8267c478bd9Sstevel@tonic-gate 	ksp = kstat_create(BGE_DRIVER_NAME, instance, name, "net",
8277c478bd9Sstevel@tonic-gate 		KSTAT_TYPE_NAMED, PARAM_COUNT, KSTAT_FLAG_PERSISTENT);
8287c478bd9Sstevel@tonic-gate 	if (ksp != NULL) {
8297c478bd9Sstevel@tonic-gate 		ksp->ks_private = bgep;
8307c478bd9Sstevel@tonic-gate 		ksp->ks_update = update;
8317c478bd9Sstevel@tonic-gate 		for (knp = ksp->ks_data, i = 0; i < PARAM_COUNT; ++knp, ++i)
8327c478bd9Sstevel@tonic-gate 			kstat_named_init(knp, bgep->nd_params[i].ndp_name+1,
8337c478bd9Sstevel@tonic-gate 				KSTAT_DATA_UINT64);
8347c478bd9Sstevel@tonic-gate 		kstat_install(ksp);
8357c478bd9Sstevel@tonic-gate 	}
8367c478bd9Sstevel@tonic-gate 
8377c478bd9Sstevel@tonic-gate 	return (ksp);
8387c478bd9Sstevel@tonic-gate }
8397c478bd9Sstevel@tonic-gate 
8407c478bd9Sstevel@tonic-gate void
8417c478bd9Sstevel@tonic-gate bge_init_kstats(bge_t *bgep, int instance)
8427c478bd9Sstevel@tonic-gate {
8437c478bd9Sstevel@tonic-gate 	kstat_t *ksp;
8447c478bd9Sstevel@tonic-gate 
8457c478bd9Sstevel@tonic-gate 	BGE_TRACE(("bge_init_kstats($%p, %d)", (void *)bgep, instance));
8467c478bd9Sstevel@tonic-gate 
8478eb6c4f9Sly149593 	if (bgep->chipid.statistic_type == BGE_STAT_BLK) {
8487c478bd9Sstevel@tonic-gate 		DMA_ZERO(bgep->statistics);
8498eb6c4f9Sly149593 		bgep->bge_kstats[BGE_KSTAT_RAW] = ksp =
8508eb6c4f9Sly149593 			kstat_create(BGE_DRIVER_NAME, instance,
8518eb6c4f9Sly149593 				"raw_statistics", "net", KSTAT_TYPE_RAW,
8527c478bd9Sstevel@tonic-gate 				sizeof (bge_statistics_t), KSTAT_FLAG_VIRTUAL);
8537c478bd9Sstevel@tonic-gate 		if (ksp != NULL) {
8547c478bd9Sstevel@tonic-gate 			ksp->ks_data = DMA_VPTR(bgep->statistics);
8557c478bd9Sstevel@tonic-gate 			kstat_install(ksp);
8567c478bd9Sstevel@tonic-gate 		}
8577c478bd9Sstevel@tonic-gate 
8587c478bd9Sstevel@tonic-gate 		bgep->bge_kstats[BGE_KSTAT_STATS] = bge_setup_named_kstat(bgep,
8597c478bd9Sstevel@tonic-gate 			instance, "statistics", bge_statistics,
8607c478bd9Sstevel@tonic-gate 			sizeof (bge_statistics), bge_statistics_update);
8618eb6c4f9Sly149593 	} else {
8628eb6c4f9Sly149593 		bgep->bge_kstats[BGE_KSTAT_STATS] = bge_setup_named_kstat(bgep,
8638eb6c4f9Sly149593 			instance, "statistics", bge_stat_val,
8648eb6c4f9Sly149593 			sizeof (bge_stat_val), bge_statistics_update);
8658eb6c4f9Sly149593 	}
8667c478bd9Sstevel@tonic-gate 
8677c478bd9Sstevel@tonic-gate 	bgep->bge_kstats[BGE_KSTAT_CHIPID] = bge_setup_named_kstat(bgep,
8687c478bd9Sstevel@tonic-gate 		instance, "chipid", bge_chipid,
8697c478bd9Sstevel@tonic-gate 		sizeof (bge_chipid), bge_chipid_update);
8707c478bd9Sstevel@tonic-gate 
8717c478bd9Sstevel@tonic-gate 	bgep->bge_kstats[BGE_KSTAT_DRIVER] = bge_setup_named_kstat(bgep,
8727c478bd9Sstevel@tonic-gate 		instance, "driverinfo", bge_driverinfo,
8737c478bd9Sstevel@tonic-gate 		sizeof (bge_driverinfo), bge_driverinfo_update);
8747c478bd9Sstevel@tonic-gate 
8757c478bd9Sstevel@tonic-gate 	bgep->bge_kstats[BGE_KSTAT_MII] = bge_setup_named_kstat(bgep,
8767c478bd9Sstevel@tonic-gate 		instance, "mii", bge_mii_kstats,
8777c478bd9Sstevel@tonic-gate 		sizeof (bge_mii_kstats), bge_mii_update);
8787c478bd9Sstevel@tonic-gate 
8797c478bd9Sstevel@tonic-gate 	if (bgep->chipid.flags & CHIP_FLAG_SERDES)
8807c478bd9Sstevel@tonic-gate 		bgep->bge_kstats[BGE_KSTAT_PHYS] = bge_setup_named_kstat(bgep,
8817c478bd9Sstevel@tonic-gate 			instance, "serdes", bge_serdes,
8827c478bd9Sstevel@tonic-gate 			sizeof (bge_serdes), bge_serdes_update);
8837c478bd9Sstevel@tonic-gate 	else
8847c478bd9Sstevel@tonic-gate 		bgep->bge_kstats[BGE_KSTAT_PHYS] = bge_setup_named_kstat(bgep,
8857c478bd9Sstevel@tonic-gate 			instance, "phydata", bge_phydata,
8867c478bd9Sstevel@tonic-gate 			sizeof (bge_phydata), bge_phydata_update);
8877c478bd9Sstevel@tonic-gate 
8887c478bd9Sstevel@tonic-gate 	bgep->bge_kstats[BGE_KSTAT_PARAMS] = bge_setup_params_kstat(bgep,
8897c478bd9Sstevel@tonic-gate 		instance, "parameters", bge_params_update);
8907c478bd9Sstevel@tonic-gate }
8917c478bd9Sstevel@tonic-gate 
8927c478bd9Sstevel@tonic-gate void
8937c478bd9Sstevel@tonic-gate bge_fini_kstats(bge_t *bgep)
8947c478bd9Sstevel@tonic-gate {
8957c478bd9Sstevel@tonic-gate 	int i;
8967c478bd9Sstevel@tonic-gate 
8977c478bd9Sstevel@tonic-gate 	BGE_TRACE(("bge_fini_kstats($%p)", (void *)bgep));
8987c478bd9Sstevel@tonic-gate 
8997c478bd9Sstevel@tonic-gate 	for (i = BGE_KSTAT_COUNT; --i >= 0; )
9007c478bd9Sstevel@tonic-gate 		if (bgep->bge_kstats[i] != NULL)
9017c478bd9Sstevel@tonic-gate 			kstat_delete(bgep->bge_kstats[i]);
9027c478bd9Sstevel@tonic-gate }
9037c478bd9Sstevel@tonic-gate 
904ba2e4443Sseb int
905ba2e4443Sseb bge_m_stat(void *arg, uint_t stat, uint64_t *val)
9067c478bd9Sstevel@tonic-gate {
9077c478bd9Sstevel@tonic-gate 	bge_t *bgep = arg;
9088eb6c4f9Sly149593 	bge_statistics_t *bstp;
909931dca7dSgs150176 	bge_statistics_reg_t *pstats;
9107c478bd9Sstevel@tonic-gate 
91100d0963fSdilpreet 	if (bgep->bge_chip_state == BGE_CHIP_FAULT) {
912ba2e4443Sseb 		return (EINVAL);
913ba2e4443Sseb 	}
914ba2e4443Sseb 
915ba2e4443Sseb 	/*
916ba2e4443Sseb 	 * The MII/GMII physical layer 802.3 stats are not supported by the
917ba2e4443Sseb 	 * bge optical interface.
918ba2e4443Sseb 	 */
919ba2e4443Sseb 	if ((bgep->chipid.flags & CHIP_FLAG_SERDES) && ETHER_STAT_ISMII(stat)) {
920ba2e4443Sseb 		return (ENOTSUP);
92100d0963fSdilpreet 	}
92200d0963fSdilpreet 
9238eb6c4f9Sly149593 	if (bgep->chipid.statistic_type == BGE_STAT_BLK)
9248eb6c4f9Sly149593 		bstp = DMA_VPTR(bgep->statistics);
9258eb6c4f9Sly149593 	else {
926931dca7dSgs150176 		pstats = bgep->pstats;
927931dca7dSgs150176 		pstats->ifHCOutOctets +=
9288eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_IFHCOUT_OCTETS_REG);
929931dca7dSgs150176 		pstats->etherStatsCollisions +=
9308eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_ETHER_COLLIS_REG);
931931dca7dSgs150176 		pstats->outXonSent +=
9328eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_OUTXON_SENT_REG);
933931dca7dSgs150176 		pstats->outXoffSent +=
9348eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_OUTXOFF_SENT_REG);
935931dca7dSgs150176 		pstats->dot3StatsInternalMacTransmitErrors +=
9368eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_DOT3_INTMACTX_ERR_REG);
937931dca7dSgs150176 		pstats->dot3StatsSingleCollisionFrames +=
9388eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_DOT3_SCOLLI_FRAME_REG);
939931dca7dSgs150176 		pstats->dot3StatsMultipleCollisionFrames +=
9408eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_DOT3_MCOLLI_FRAME_REG);
941931dca7dSgs150176 		pstats->dot3StatsDeferredTransmissions +=
9428eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_DOT3_DEFERED_TX_REG);
943931dca7dSgs150176 		pstats->dot3StatsExcessiveCollisions +=
9448eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_DOT3_EXCE_COLLI_REG);
945931dca7dSgs150176 		pstats->dot3StatsLateCollisions +=
9468eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_DOT3_LATE_COLLI_REG);
947931dca7dSgs150176 		pstats->ifHCOutUcastPkts +=
9488eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_IFHCOUT_UPKGS_REG);
949931dca7dSgs150176 		pstats->ifHCOutMulticastPkts +=
9508eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_IFHCOUT_MPKGS_REG);
951931dca7dSgs150176 		pstats->ifHCOutBroadcastPkts +=
9528eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_IFHCOUT_BPKGS_REG);
953931dca7dSgs150176 		pstats->ifHCInOctets +=
9548eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_IFHCIN_OCTETS_REG);
955931dca7dSgs150176 		pstats->etherStatsFragments +=
9568eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_ETHER_FRAGMENT_REG);
957931dca7dSgs150176 		pstats->ifHCInUcastPkts +=
9588eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_IFHCIN_UPKGS_REG);
959931dca7dSgs150176 		pstats->ifHCInMulticastPkts +=
9608eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_IFHCIN_MPKGS_REG);
961931dca7dSgs150176 		pstats->ifHCInBroadcastPkts +=
9628eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_IFHCIN_BPKGS_REG);
963931dca7dSgs150176 		pstats->dot3StatsFCSErrors +=
9648eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_DOT3_FCS_ERR_REG);
965931dca7dSgs150176 		pstats->dot3StatsAlignmentErrors +=
9668eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_DOT3_ALIGN_ERR_REG);
967931dca7dSgs150176 		pstats->xonPauseFramesReceived +=
9688eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_XON_PAUSE_RX_REG);
969931dca7dSgs150176 		pstats->xoffPauseFramesReceived +=
9708eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_XOFF_PAUSE_RX_REG);
971931dca7dSgs150176 		pstats->macControlFramesReceived +=
9728eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_MAC_CTRL_RX_REG);
973931dca7dSgs150176 		pstats->xoffStateEntered +=
9748eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_XOFF_STATE_ENTER_REG);
975931dca7dSgs150176 		pstats->dot3StatsFrameTooLongs +=
9768eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_DOT3_FRAME_TOOLONG_REG);
977931dca7dSgs150176 		pstats->etherStatsJabbers +=
9788eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_ETHER_JABBERS_REG);
979931dca7dSgs150176 		pstats->etherStatsUndersizePkts +=
9808eb6c4f9Sly149593 		    bge_reg_get32(bgep, STAT_ETHER_UNDERSIZE_REG);
981f724721bSzh199473 		mutex_enter(bgep->genlock);
98200d0963fSdilpreet 		if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) {
98300d0963fSdilpreet 			ddi_fm_service_impact(bgep->devinfo,
98400d0963fSdilpreet 			    DDI_SERVICE_UNAFFECTED);
98500d0963fSdilpreet 		}
986f724721bSzh199473 		mutex_exit(bgep->genlock);
9878eb6c4f9Sly149593 	}
9888eb6c4f9Sly149593 
9897c478bd9Sstevel@tonic-gate 	switch (stat) {
9907c478bd9Sstevel@tonic-gate 	case MAC_STAT_IFSPEED:
991ba2e4443Sseb 		*val = bgep->param_link_speed * 1000000ull;
9927c478bd9Sstevel@tonic-gate 		break;
9937c478bd9Sstevel@tonic-gate 
9947c478bd9Sstevel@tonic-gate 	case MAC_STAT_MULTIRCV:
9958eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
996ba2e4443Sseb 			*val = bstp->s.ifHCInMulticastPkts;
9978eb6c4f9Sly149593 		else
998931dca7dSgs150176 			*val = pstats->ifHCInMulticastPkts;
9997c478bd9Sstevel@tonic-gate 		break;
10007c478bd9Sstevel@tonic-gate 
10017c478bd9Sstevel@tonic-gate 	case MAC_STAT_BRDCSTRCV:
10028eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1003ba2e4443Sseb 			*val = bstp->s.ifHCInBroadcastPkts;
10048eb6c4f9Sly149593 		else
1005931dca7dSgs150176 			*val = pstats->ifHCInBroadcastPkts;
10067c478bd9Sstevel@tonic-gate 		break;
10077c478bd9Sstevel@tonic-gate 
10087c478bd9Sstevel@tonic-gate 	case MAC_STAT_MULTIXMT:
10098eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1010ba2e4443Sseb 			*val = bstp->s.ifHCOutMulticastPkts;
10118eb6c4f9Sly149593 		else
1012931dca7dSgs150176 			*val = pstats->ifHCOutMulticastPkts;
10137c478bd9Sstevel@tonic-gate 		break;
10147c478bd9Sstevel@tonic-gate 
10157c478bd9Sstevel@tonic-gate 	case MAC_STAT_BRDCSTXMT:
10168eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1017ba2e4443Sseb 			*val = bstp->s.ifHCOutBroadcastPkts;
10188eb6c4f9Sly149593 		else
1019931dca7dSgs150176 			*val = pstats->ifHCOutBroadcastPkts;
10207c478bd9Sstevel@tonic-gate 		break;
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate 	case MAC_STAT_NORCVBUF:
10238eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1024ba2e4443Sseb 			*val = bstp->s.ifInDiscards;
10258eb6c4f9Sly149593 		else
1026ba2e4443Sseb 			*val = 0;
10277c478bd9Sstevel@tonic-gate 		break;
10287c478bd9Sstevel@tonic-gate 
10297c478bd9Sstevel@tonic-gate 	case MAC_STAT_IERRORS:
1030ba2e4443Sseb 		if (bgep->chipid.statistic_type == BGE_STAT_BLK) {
1031ba2e4443Sseb 			*val = bstp->s.dot3StatsFCSErrors +
10323c46fd93Szh199473 			    bstp->s.dot3StatsAlignmentErrors +
10333c46fd93Szh199473 			    bstp->s.dot3StatsFrameTooLongs +
10343c46fd93Szh199473 			    bstp->s.etherStatsUndersizePkts +
10353c46fd93Szh199473 			    bstp->s.etherStatsJabbers;
1036ba2e4443Sseb 		} else {
1037931dca7dSgs150176 			*val = pstats->dot3StatsFCSErrors +
1038931dca7dSgs150176 			    pstats->dot3StatsAlignmentErrors +
1039931dca7dSgs150176 			    pstats->dot3StatsFrameTooLongs +
1040931dca7dSgs150176 			    pstats->etherStatsUndersizePkts +
1041931dca7dSgs150176 			    pstats->etherStatsJabbers;
1042ba2e4443Sseb 		}
10437c478bd9Sstevel@tonic-gate 		break;
10447c478bd9Sstevel@tonic-gate 
10457c478bd9Sstevel@tonic-gate 	case MAC_STAT_NOXMTBUF:
10468eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1047ba2e4443Sseb 			*val = bstp->s.ifOutDiscards;
10488eb6c4f9Sly149593 		else
1049ba2e4443Sseb 			*val = 0;
10507c478bd9Sstevel@tonic-gate 		break;
10517c478bd9Sstevel@tonic-gate 
10527c478bd9Sstevel@tonic-gate 	case MAC_STAT_OERRORS:
10538eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1054ba2e4443Sseb 			*val = bstp->s.ifOutDiscards;
10558eb6c4f9Sly149593 		else
1056ba2e4443Sseb 			*val = 0;
10577c478bd9Sstevel@tonic-gate 		break;
10587c478bd9Sstevel@tonic-gate 
10597c478bd9Sstevel@tonic-gate 	case MAC_STAT_COLLISIONS:
10608eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1061ba2e4443Sseb 			*val = bstp->s.etherStatsCollisions;
10628eb6c4f9Sly149593 		else
1063931dca7dSgs150176 			*val = pstats->etherStatsCollisions;
10647c478bd9Sstevel@tonic-gate 		break;
10657c478bd9Sstevel@tonic-gate 
10667c478bd9Sstevel@tonic-gate 	case MAC_STAT_RBYTES:
10678eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1068ba2e4443Sseb 			*val = bstp->s.ifHCInOctets;
10698eb6c4f9Sly149593 		else
1070931dca7dSgs150176 			*val = pstats->ifHCInOctets;
10717c478bd9Sstevel@tonic-gate 		break;
10727c478bd9Sstevel@tonic-gate 
10737c478bd9Sstevel@tonic-gate 	case MAC_STAT_IPACKETS:
10748eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1075ba2e4443Sseb 			*val = bstp->s.ifHCInUcastPkts +
10767c478bd9Sstevel@tonic-gate 			    bstp->s.ifHCInMulticastPkts +
10777c478bd9Sstevel@tonic-gate 			    bstp->s.ifHCInBroadcastPkts;
10788eb6c4f9Sly149593 		else
1079931dca7dSgs150176 			*val = pstats->ifHCInUcastPkts +
1080931dca7dSgs150176 			    pstats->ifHCInMulticastPkts +
1081931dca7dSgs150176 			    pstats->ifHCInBroadcastPkts;
10827c478bd9Sstevel@tonic-gate 		break;
10837c478bd9Sstevel@tonic-gate 
10847c478bd9Sstevel@tonic-gate 	case MAC_STAT_OBYTES:
10858eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1086ba2e4443Sseb 			*val = bstp->s.ifHCOutOctets;
10878eb6c4f9Sly149593 		else
1088931dca7dSgs150176 			*val = pstats->ifHCOutOctets;
10897c478bd9Sstevel@tonic-gate 		break;
10907c478bd9Sstevel@tonic-gate 
10917c478bd9Sstevel@tonic-gate 	case MAC_STAT_OPACKETS:
10928eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1093ba2e4443Sseb 			*val = bstp->s.ifHCOutUcastPkts +
10947c478bd9Sstevel@tonic-gate 			    bstp->s.ifHCOutMulticastPkts +
10957c478bd9Sstevel@tonic-gate 			    bstp->s.ifHCOutBroadcastPkts;
10968eb6c4f9Sly149593 		else
1097931dca7dSgs150176 			*val = pstats->ifHCOutUcastPkts +
1098931dca7dSgs150176 			    pstats->ifHCOutMulticastPkts +
1099931dca7dSgs150176 			    pstats->ifHCOutBroadcastPkts;
11007c478bd9Sstevel@tonic-gate 		break;
11017c478bd9Sstevel@tonic-gate 
1102ba2e4443Sseb 	case ETHER_STAT_ALIGN_ERRORS:
11038eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1104ba2e4443Sseb 			*val = bstp->s.dot3StatsAlignmentErrors;
11058eb6c4f9Sly149593 		else
1106931dca7dSgs150176 			*val = pstats->dot3StatsAlignmentErrors;
11077c478bd9Sstevel@tonic-gate 		break;
11087c478bd9Sstevel@tonic-gate 
1109ba2e4443Sseb 	case ETHER_STAT_FCS_ERRORS:
11108eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1111ba2e4443Sseb 			*val = bstp->s.dot3StatsFCSErrors;
11128eb6c4f9Sly149593 		else
1113931dca7dSgs150176 			*val = pstats->dot3StatsFCSErrors;
11147c478bd9Sstevel@tonic-gate 		break;
11157c478bd9Sstevel@tonic-gate 
1116ba2e4443Sseb 	case ETHER_STAT_FIRST_COLLISIONS:
11178eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1118ba2e4443Sseb 			*val = bstp->s.dot3StatsSingleCollisionFrames;
11198eb6c4f9Sly149593 		else
1120931dca7dSgs150176 			*val = pstats->dot3StatsSingleCollisionFrames;
11217c478bd9Sstevel@tonic-gate 		break;
11227c478bd9Sstevel@tonic-gate 
1123ba2e4443Sseb 	case ETHER_STAT_MULTI_COLLISIONS:
11248eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1125ba2e4443Sseb 			*val = bstp->s.dot3StatsMultipleCollisionFrames;
11268eb6c4f9Sly149593 		else
1127931dca7dSgs150176 			*val = pstats->dot3StatsMultipleCollisionFrames;
11287c478bd9Sstevel@tonic-gate 		break;
11297c478bd9Sstevel@tonic-gate 
1130ba2e4443Sseb 	case ETHER_STAT_DEFER_XMTS:
11318eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1132ba2e4443Sseb 			*val = bstp->s.dot3StatsDeferredTransmissions;
11338eb6c4f9Sly149593 		else
1134931dca7dSgs150176 			*val = pstats->dot3StatsDeferredTransmissions;
11357c478bd9Sstevel@tonic-gate 		break;
11367c478bd9Sstevel@tonic-gate 
1137ba2e4443Sseb 	case ETHER_STAT_TX_LATE_COLLISIONS:
11388eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1139ba2e4443Sseb 			*val = bstp->s.dot3StatsLateCollisions;
11408eb6c4f9Sly149593 		else
1141931dca7dSgs150176 			*val = pstats->dot3StatsLateCollisions;
11427c478bd9Sstevel@tonic-gate 		break;
11437c478bd9Sstevel@tonic-gate 
1144ba2e4443Sseb 	case ETHER_STAT_EX_COLLISIONS:
11458eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1146ba2e4443Sseb 			*val = bstp->s.dot3StatsExcessiveCollisions;
11478eb6c4f9Sly149593 		else
1148931dca7dSgs150176 			*val = pstats->dot3StatsExcessiveCollisions;
11497c478bd9Sstevel@tonic-gate 		break;
11507c478bd9Sstevel@tonic-gate 
1151ba2e4443Sseb 	case ETHER_STAT_MACXMT_ERRORS:
11528eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1153ba2e4443Sseb 			*val = bstp->s.dot3StatsInternalMacTransmitErrors;
11548eb6c4f9Sly149593 		else
1155931dca7dSgs150176 			*val = bgep->pstats->dot3StatsInternalMacTransmitErrors;
11567c478bd9Sstevel@tonic-gate 		break;
11577c478bd9Sstevel@tonic-gate 
1158ba2e4443Sseb 	case ETHER_STAT_CARRIER_ERRORS:
11598eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1160ba2e4443Sseb 			*val = bstp->s.dot3StatsCarrierSenseErrors;
11618eb6c4f9Sly149593 		else
1162ba2e4443Sseb 			*val = 0;
11637c478bd9Sstevel@tonic-gate 		break;
11647c478bd9Sstevel@tonic-gate 
1165ba2e4443Sseb 	case ETHER_STAT_TOOLONG_ERRORS:
11668eb6c4f9Sly149593 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1167ba2e4443Sseb 			*val = bstp->s.dot3StatsFrameTooLongs;
11688eb6c4f9Sly149593 		else
1169931dca7dSgs150176 			*val = pstats->dot3StatsFrameTooLongs;
11707c478bd9Sstevel@tonic-gate 		break;
11717c478bd9Sstevel@tonic-gate 
1172*9b14cf1dSgd78059 	case ETHER_STAT_TOOSHORT_ERRORS:
1173*9b14cf1dSgd78059 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
1174*9b14cf1dSgd78059 			*val = bstp->s.etherStatsUndersizePkts;
1175*9b14cf1dSgd78059 		else
1176*9b14cf1dSgd78059 			*val = pstats->etherStatsUndersizePkts;
1177*9b14cf1dSgd78059 		break;
1178*9b14cf1dSgd78059 
1179ba2e4443Sseb 	case ETHER_STAT_XCVR_ADDR:
1180ba2e4443Sseb 		*val = bgep->phy_mii_addr;
11817c478bd9Sstevel@tonic-gate 		break;
11827c478bd9Sstevel@tonic-gate 
1183ba2e4443Sseb 	case ETHER_STAT_XCVR_ID:
1184f724721bSzh199473 		mutex_enter(bgep->genlock);
1185ba2e4443Sseb 		*val = bge_mii_get16(bgep, MII_PHYIDH);
1186ba2e4443Sseb 		*val <<= 16;
1187ba2e4443Sseb 		*val |= bge_mii_get16(bgep, MII_PHYIDL);
118800d0963fSdilpreet 		if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) {
118900d0963fSdilpreet 			ddi_fm_service_impact(bgep->devinfo,
119000d0963fSdilpreet 			    DDI_SERVICE_UNAFFECTED);
119100d0963fSdilpreet 		}
1192f724721bSzh199473 		mutex_exit(bgep->genlock);
11937c478bd9Sstevel@tonic-gate 		break;
11947c478bd9Sstevel@tonic-gate 
1195ba2e4443Sseb 	case ETHER_STAT_XCVR_INUSE:
1196ba2e4443Sseb 		*val = XCVR_1000T;
11977c478bd9Sstevel@tonic-gate 		break;
11987c478bd9Sstevel@tonic-gate 
1199ba2e4443Sseb 	case ETHER_STAT_CAP_1000FDX:
1200ba2e4443Sseb 		*val = 1;
12017c478bd9Sstevel@tonic-gate 		break;
12027c478bd9Sstevel@tonic-gate 
1203ba2e4443Sseb 	case ETHER_STAT_CAP_1000HDX:
1204ba2e4443Sseb 		*val = 1;
12057c478bd9Sstevel@tonic-gate 		break;
12067c478bd9Sstevel@tonic-gate 
1207ba2e4443Sseb 	case ETHER_STAT_CAP_100FDX:
1208ba2e4443Sseb 		*val = 1;
12097c478bd9Sstevel@tonic-gate 		break;
12107c478bd9Sstevel@tonic-gate 
1211ba2e4443Sseb 	case ETHER_STAT_CAP_100HDX:
1212ba2e4443Sseb 		*val = 1;
12137c478bd9Sstevel@tonic-gate 		break;
12147c478bd9Sstevel@tonic-gate 
1215ba2e4443Sseb 	case ETHER_STAT_CAP_10FDX:
1216ba2e4443Sseb 		*val = 1;
12177c478bd9Sstevel@tonic-gate 		break;
12187c478bd9Sstevel@tonic-gate 
1219ba2e4443Sseb 	case ETHER_STAT_CAP_10HDX:
1220ba2e4443Sseb 		*val = 1;
12217c478bd9Sstevel@tonic-gate 		break;
12227c478bd9Sstevel@tonic-gate 
1223ba2e4443Sseb 	case ETHER_STAT_CAP_ASMPAUSE:
1224ba2e4443Sseb 		*val = 1;
12257c478bd9Sstevel@tonic-gate 		break;
12267c478bd9Sstevel@tonic-gate 
1227ba2e4443Sseb 	case ETHER_STAT_CAP_PAUSE:
1228ba2e4443Sseb 		*val = 1;
12297c478bd9Sstevel@tonic-gate 		break;
12307c478bd9Sstevel@tonic-gate 
1231ba2e4443Sseb 	case ETHER_STAT_CAP_AUTONEG:
1232ba2e4443Sseb 		*val = 1;
12337c478bd9Sstevel@tonic-gate 		break;
12347c478bd9Sstevel@tonic-gate 
1235*9b14cf1dSgd78059 	case ETHER_STAT_CAP_REMFAULT:
1236*9b14cf1dSgd78059 		*val = 1;
1237*9b14cf1dSgd78059 		break;
1238*9b14cf1dSgd78059 
1239ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_1000FDX:
1240ba2e4443Sseb 		*val = bgep->param_adv_1000fdx;
12417c478bd9Sstevel@tonic-gate 		break;
12427c478bd9Sstevel@tonic-gate 
1243ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_1000HDX:
1244ba2e4443Sseb 		*val = bgep->param_adv_1000hdx;
12457c478bd9Sstevel@tonic-gate 		break;
12467c478bd9Sstevel@tonic-gate 
1247ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_100FDX:
1248ba2e4443Sseb 		*val = bgep->param_adv_100fdx;
12497c478bd9Sstevel@tonic-gate 		break;
12507c478bd9Sstevel@tonic-gate 
1251ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_100HDX:
1252ba2e4443Sseb 		*val = bgep->param_adv_100hdx;
12537c478bd9Sstevel@tonic-gate 		break;
12547c478bd9Sstevel@tonic-gate 
1255ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_10FDX:
1256ba2e4443Sseb 		*val = bgep->param_adv_10fdx;
12577c478bd9Sstevel@tonic-gate 		break;
12587c478bd9Sstevel@tonic-gate 
1259ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_10HDX:
1260ba2e4443Sseb 		*val = bgep->param_adv_10hdx;
12617c478bd9Sstevel@tonic-gate 		break;
12627c478bd9Sstevel@tonic-gate 
1263ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_ASMPAUSE:
1264ba2e4443Sseb 		*val = bgep->param_adv_asym_pause;
12657c478bd9Sstevel@tonic-gate 		break;
12667c478bd9Sstevel@tonic-gate 
1267ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_PAUSE:
1268ba2e4443Sseb 		*val = bgep->param_adv_pause;
12697c478bd9Sstevel@tonic-gate 		break;
12707c478bd9Sstevel@tonic-gate 
1271ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_AUTONEG:
1272ba2e4443Sseb 		*val = bgep->param_adv_autoneg;
12737c478bd9Sstevel@tonic-gate 		break;
12747c478bd9Sstevel@tonic-gate 
1275*9b14cf1dSgd78059 	case ETHER_STAT_ADV_REMFAULT:
1276*9b14cf1dSgd78059 		mutex_enter(bgep->genlock);
1277*9b14cf1dSgd78059 		*val = bge_mii_get16(bgep, MII_AN_ADVERT) &
1278*9b14cf1dSgd78059 		    MII_AN_ADVERT_REMFAULT ? 1 : 0;
1279*9b14cf1dSgd78059 		if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) {
1280*9b14cf1dSgd78059 			ddi_fm_service_impact(bgep->devinfo,
1281*9b14cf1dSgd78059 			    DDI_SERVICE_UNAFFECTED);
1282*9b14cf1dSgd78059 		}
1283*9b14cf1dSgd78059 		mutex_exit(bgep->genlock);
1284*9b14cf1dSgd78059 		break;
1285*9b14cf1dSgd78059 
1286ba2e4443Sseb 	case ETHER_STAT_LP_CAP_1000FDX:
1287ba2e4443Sseb 		*val = bgep->param_lp_1000fdx;
12887c478bd9Sstevel@tonic-gate 		break;
12897c478bd9Sstevel@tonic-gate 
1290ba2e4443Sseb 	case ETHER_STAT_LP_CAP_1000HDX:
1291ba2e4443Sseb 		*val = bgep->param_lp_1000hdx;
12927c478bd9Sstevel@tonic-gate 		break;
12937c478bd9Sstevel@tonic-gate 
1294ba2e4443Sseb 	case ETHER_STAT_LP_CAP_100FDX:
1295ba2e4443Sseb 		*val = bgep->param_lp_100fdx;
12967c478bd9Sstevel@tonic-gate 		break;
12977c478bd9Sstevel@tonic-gate 
1298ba2e4443Sseb 	case ETHER_STAT_LP_CAP_100HDX:
1299ba2e4443Sseb 		*val = bgep->param_lp_100hdx;
13007c478bd9Sstevel@tonic-gate 		break;
13017c478bd9Sstevel@tonic-gate 
1302ba2e4443Sseb 	case ETHER_STAT_LP_CAP_10FDX:
1303ba2e4443Sseb 		*val = bgep->param_lp_10fdx;
13047c478bd9Sstevel@tonic-gate 		break;
13057c478bd9Sstevel@tonic-gate 
1306ba2e4443Sseb 	case ETHER_STAT_LP_CAP_10HDX:
1307ba2e4443Sseb 		*val = bgep->param_lp_10hdx;
13087c478bd9Sstevel@tonic-gate 		break;
13097c478bd9Sstevel@tonic-gate 
1310ba2e4443Sseb 	case ETHER_STAT_LP_CAP_ASMPAUSE:
1311ba2e4443Sseb 		*val = bgep->param_lp_asym_pause;
13127c478bd9Sstevel@tonic-gate 		break;
13137c478bd9Sstevel@tonic-gate 
1314ba2e4443Sseb 	case ETHER_STAT_LP_CAP_PAUSE:
1315ba2e4443Sseb 		*val = bgep->param_lp_pause;
13167c478bd9Sstevel@tonic-gate 		break;
13177c478bd9Sstevel@tonic-gate 
1318ba2e4443Sseb 	case ETHER_STAT_LP_CAP_AUTONEG:
1319ba2e4443Sseb 		*val = bgep->param_lp_autoneg;
13207c478bd9Sstevel@tonic-gate 		break;
13217c478bd9Sstevel@tonic-gate 
1322*9b14cf1dSgd78059 	case ETHER_STAT_LP_REMFAULT:
1323*9b14cf1dSgd78059 		mutex_enter(bgep->genlock);
1324*9b14cf1dSgd78059 		*val = bge_mii_get16(bgep, MII_AN_LPABLE) &
1325*9b14cf1dSgd78059 		    MII_AN_ADVERT_REMFAULT ? 1 : 0;
1326*9b14cf1dSgd78059 		if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) {
1327*9b14cf1dSgd78059 			ddi_fm_service_impact(bgep->devinfo,
1328*9b14cf1dSgd78059 			    DDI_SERVICE_UNAFFECTED);
1329*9b14cf1dSgd78059 		}
1330*9b14cf1dSgd78059 		mutex_exit(bgep->genlock);
1331*9b14cf1dSgd78059 		break;
1332*9b14cf1dSgd78059 
1333ba2e4443Sseb 	case ETHER_STAT_LINK_ASMPAUSE:
1334ba2e4443Sseb 		*val = bgep->param_adv_asym_pause &&
13357c478bd9Sstevel@tonic-gate 		    bgep->param_lp_asym_pause &&
13367c478bd9Sstevel@tonic-gate 		    bgep->param_adv_pause != bgep->param_lp_pause;
13377c478bd9Sstevel@tonic-gate 		break;
13387c478bd9Sstevel@tonic-gate 
1339ba2e4443Sseb 	case ETHER_STAT_LINK_PAUSE:
1340ba2e4443Sseb 		*val = bgep->param_link_rx_pause;
13417c478bd9Sstevel@tonic-gate 		break;
13427c478bd9Sstevel@tonic-gate 
1343ba2e4443Sseb 	case ETHER_STAT_LINK_AUTONEG:
1344ba2e4443Sseb 		*val = bgep->param_link_autoneg;
13457c478bd9Sstevel@tonic-gate 		break;
13467c478bd9Sstevel@tonic-gate 
1347ba2e4443Sseb 	case ETHER_STAT_LINK_DUPLEX:
1348ba2e4443Sseb 		*val = bgep->param_link_duplex;
13497c478bd9Sstevel@tonic-gate 		break;
13507c478bd9Sstevel@tonic-gate 
13517c478bd9Sstevel@tonic-gate 	default:
1352ba2e4443Sseb 		return (ENOTSUP);
13537c478bd9Sstevel@tonic-gate 	}
13547c478bd9Sstevel@tonic-gate 
1355ba2e4443Sseb 	return (0);
13567c478bd9Sstevel@tonic-gate }
1357