xref: /illumos-gate/usr/src/uts/common/io/bge/bge_kstats.c (revision 87a49193)
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 
22087a28d1SDavid Gwynne /*
23087a28d1SDavid Gwynne  * Copyright (c) 2010-2013, by Broadcom, Inc.
24087a28d1SDavid Gwynne  * All Rights Reserved.
25087a28d1SDavid Gwynne  */
26087a28d1SDavid Gwynne 
277c478bd9Sstevel@tonic-gate /*
280dc2366fSVenugopal Iyer  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
297c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
32f724721bSzh #include "bge_impl.h"
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #define	BGE_DBG		BGE_DBG_STATS	/* debug flag for this code	*/
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * Local datatype for defining tables of (Offset, Name) pairs
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate typedef struct {
407c478bd9Sstevel@tonic-gate 	offset_t	index;
417c478bd9Sstevel@tonic-gate 	char		*name;
427c478bd9Sstevel@tonic-gate } bge_ksindex_t;
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * Table of Hardware-defined Statistics Block Offsets and Names
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate #define	KS_NAME(s)			{ KS_ ## s, #s }
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate static const bge_ksindex_t bge_statistics[] = {
517c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCInOctets),
527c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsFragments),
537c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCInUcastPkts),
547c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCInMulticastPkts),
557c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCInBroadcastPkts),
567c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsFCSErrors),
577c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsAlignmentErrors),
587c478bd9Sstevel@tonic-gate 	KS_NAME(xonPauseFramesReceived),
597c478bd9Sstevel@tonic-gate 	KS_NAME(xoffPauseFramesReceived),
607c478bd9Sstevel@tonic-gate 	KS_NAME(macControlFramesReceived),
617c478bd9Sstevel@tonic-gate 	KS_NAME(xoffStateEntered),
627c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsFrameTooLongs),
637c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsJabbers),
647c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsUndersizePkts),
657c478bd9Sstevel@tonic-gate 	KS_NAME(inRangeLengthError),
667c478bd9Sstevel@tonic-gate 	KS_NAME(outRangeLengthError),
677c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts64Octets),
687c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts65to127Octets),
697c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts128to255Octets),
707c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts256to511Octets),
717c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts512to1023Octets),
727c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts1024to1518Octets),
737c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts1519to2047Octets),
747c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts2048to4095Octets),
757c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts4096to8191Octets),
767c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsPkts8192to9022Octets),
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCOutOctets),
797c478bd9Sstevel@tonic-gate 	KS_NAME(etherStatsCollisions),
807c478bd9Sstevel@tonic-gate 	KS_NAME(outXonSent),
817c478bd9Sstevel@tonic-gate 	KS_NAME(outXoffSent),
827c478bd9Sstevel@tonic-gate 	KS_NAME(flowControlDone),
837c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsInternalMacTransmitErrors),
847c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsSingleCollisionFrames),
857c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsMultipleCollisionFrames),
867c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsDeferredTransmissions),
877c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsExcessiveCollisions),
887c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsLateCollisions),
897c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided2Times),
907c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided3Times),
917c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided4Times),
927c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided5Times),
937c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided6Times),
947c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided7Times),
957c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided8Times),
967c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided9Times),
977c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided10Times),
987c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided11Times),
997c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided12Times),
1007c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided13Times),
1017c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided14Times),
1027c478bd9Sstevel@tonic-gate 	KS_NAME(dot3Collided15Times),
1037c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCOutUcastPkts),
1047c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCOutMulticastPkts),
1057c478bd9Sstevel@tonic-gate 	KS_NAME(ifHCOutBroadcastPkts),
1067c478bd9Sstevel@tonic-gate 	KS_NAME(dot3StatsCarrierSenseErrors),
1077c478bd9Sstevel@tonic-gate 	KS_NAME(ifOutDiscards),
1087c478bd9Sstevel@tonic-gate 	KS_NAME(ifOutErrors),
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_1),
1117c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_2),
1127c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_3),
1137c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_4),
1147c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_5),
1157c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_6),
1167c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_7),
1177c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_8),
1187c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_9),
1197c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_10),
1207c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_11),
1217c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_12),
1227c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_13),
1237c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_14),
1247c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_15),
1257c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCInPkts_16),
1267c478bd9Sstevel@tonic-gate 	KS_NAME(COSFramesDroppedDueToFilters),
1277c478bd9Sstevel@tonic-gate 	KS_NAME(nicDmaWriteQueueFull),
1287c478bd9Sstevel@tonic-gate 	KS_NAME(nicDmaWriteHighPriQueueFull),
1297c478bd9Sstevel@tonic-gate 	KS_NAME(nicNoMoreRxBDs),
1307c478bd9Sstevel@tonic-gate 	KS_NAME(ifInDiscards),
1317c478bd9Sstevel@tonic-gate 	KS_NAME(ifInErrors),
1327c478bd9Sstevel@tonic-gate 	KS_NAME(nicRecvThresholdHit),
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_1),
1357c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_2),
1367c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_3),
1377c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_4),
1387c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_5),
1397c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_6),
1407c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_7),
1417c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_8),
1427c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_9),
1437c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_10),
1447c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_11),
1457c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_12),
1467c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_13),
1477c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_14),
1487c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_15),
1497c478bd9Sstevel@tonic-gate 	KS_NAME(COSIfHCOutPkts_16),
1507c478bd9Sstevel@tonic-gate 	KS_NAME(nicDmaReadQueueFull),
1517c478bd9Sstevel@tonic-gate 	KS_NAME(nicDmaReadHighPriQueueFull),
1527c478bd9Sstevel@tonic-gate 	KS_NAME(nicSendDataCompQueueFull),
1537c478bd9Sstevel@tonic-gate 	KS_NAME(nicRingSetSendProdIndex),
1547c478bd9Sstevel@tonic-gate 	KS_NAME(nicRingStatusUpdate),
1557c478bd9Sstevel@tonic-gate 	KS_NAME(nicInterrupts),
1567c478bd9Sstevel@tonic-gate 	KS_NAME(nicAvoidedInterrupts),
1577c478bd9Sstevel@tonic-gate 	KS_NAME(nicSendThresholdHit),
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate 	{ KS_STATS_SIZE, NULL }
1607c478bd9Sstevel@tonic-gate };
1617c478bd9Sstevel@tonic-gate 
1628eb6c4f9Sly static const bge_ksindex_t bge_stat_val[] = {
1638eb6c4f9Sly 	KS_NAME(ifHCOutOctets),
1648eb6c4f9Sly 	KS_NAME(etherStatsCollisions),
1658eb6c4f9Sly 	KS_NAME(outXonSent),
1668eb6c4f9Sly 	KS_NAME(outXoffSent),
1678eb6c4f9Sly 	KS_NAME(dot3StatsInternalMacTransmitErrors),
1688eb6c4f9Sly 	KS_NAME(dot3StatsSingleCollisionFrames),
1698eb6c4f9Sly 	KS_NAME(dot3StatsMultipleCollisionFrames),
1708eb6c4f9Sly 	KS_NAME(dot3StatsDeferredTransmissions),
1718eb6c4f9Sly 	KS_NAME(dot3StatsExcessiveCollisions),
1728eb6c4f9Sly 	KS_NAME(dot3StatsLateCollisions),
1738eb6c4f9Sly 	KS_NAME(ifHCOutUcastPkts),
1748eb6c4f9Sly 	KS_NAME(ifHCOutMulticastPkts),
1758eb6c4f9Sly 	KS_NAME(ifHCOutBroadcastPkts),
1768eb6c4f9Sly 	KS_NAME(ifHCInOctets),
1778eb6c4f9Sly 	KS_NAME(etherStatsFragments),
1788eb6c4f9Sly 	KS_NAME(ifHCInUcastPkts),
1798eb6c4f9Sly 	KS_NAME(ifHCInMulticastPkts),
1808eb6c4f9Sly 	KS_NAME(ifHCInBroadcastPkts),
1818eb6c4f9Sly 	KS_NAME(dot3StatsFCSErrors),
1828eb6c4f9Sly 	KS_NAME(dot3StatsAlignmentErrors),
1838eb6c4f9Sly 	KS_NAME(xonPauseFramesReceived),
1848eb6c4f9Sly 	KS_NAME(xoffPauseFramesReceived),
1858eb6c4f9Sly 	KS_NAME(macControlFramesReceived),
1868eb6c4f9Sly 	KS_NAME(xoffStateEntered),
1878eb6c4f9Sly 	KS_NAME(dot3StatsFrameTooLongs),
1888eb6c4f9Sly 	KS_NAME(etherStatsJabbers),
1898eb6c4f9Sly 	KS_NAME(etherStatsUndersizePkts),
1908eb6c4f9Sly 
1918eb6c4f9Sly 	{ KS_STAT_REG_SIZE, NULL }
1928eb6c4f9Sly };
1938eb6c4f9Sly 
1947c478bd9Sstevel@tonic-gate static int
bge_statistics_update(kstat_t * ksp,int flag)1957c478bd9Sstevel@tonic-gate bge_statistics_update(kstat_t *ksp, int flag)
1967c478bd9Sstevel@tonic-gate {
1977c478bd9Sstevel@tonic-gate 	bge_t *bgep;
1987c478bd9Sstevel@tonic-gate 	bge_statistics_t *bstp;
199931dca7dSgs 	bge_statistics_reg_t *pstats;
2007c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
2017c478bd9Sstevel@tonic-gate 	const bge_ksindex_t *ksip;
2027c478bd9Sstevel@tonic-gate 
2037c478bd9Sstevel@tonic-gate 	if (flag != KSTAT_READ)
2047c478bd9Sstevel@tonic-gate 		return (EACCES);
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	bgep = ksp->ks_private;
2078eb6c4f9Sly 	if (bgep->chipid.statistic_type == BGE_STAT_BLK)
2088eb6c4f9Sly 		bstp = DMA_VPTR(bgep->statistics);
2098eb6c4f9Sly 
2107c478bd9Sstevel@tonic-gate 	knp = ksp->ks_data;
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	/*
2137c478bd9Sstevel@tonic-gate 	 * Transfer the statistics values from the copy that the
2147c478bd9Sstevel@tonic-gate 	 * chip updates via DMA to the named-kstat structure.
2157c478bd9Sstevel@tonic-gate 	 *
2167c478bd9Sstevel@tonic-gate 	 * As above, we don't bother to sync or stop updates to the
2177c478bd9Sstevel@tonic-gate 	 * statistics, 'cos it doesn't really matter if they're a few
218256e438eSzh 	 * microseconds out of date or less than 100% consistent ...
2197c478bd9Sstevel@tonic-gate 	 */
2208eb6c4f9Sly 	if (bgep->chipid.statistic_type == BGE_STAT_BLK)
2218eb6c4f9Sly 		for (ksip = bge_statistics; ksip->name != NULL; ++knp, ++ksip)
2228eb6c4f9Sly 			knp->value.ui64 = bstp->a[ksip->index];
2238eb6c4f9Sly 	else {
224931dca7dSgs 		pstats = bgep->pstats;
225931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCOutOctets);
226931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->etherStatsCollisions);
227931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->outXonSent);
228931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->outXoffSent);
2298eb6c4f9Sly 		(knp++)->value.ui64 =
230931dca7dSgs 		    (uint64_t)(pstats->dot3StatsInternalMacTransmitErrors);
2318eb6c4f9Sly 		(knp++)->value.ui64 =
232931dca7dSgs 		    (uint64_t)(pstats->dot3StatsSingleCollisionFrames);
2338eb6c4f9Sly 		(knp++)->value.ui64 =
234931dca7dSgs 		    (uint64_t)(pstats->dot3StatsMultipleCollisionFrames);
2358eb6c4f9Sly 		(knp++)->value.ui64 =
236931dca7dSgs 		    (uint64_t)(pstats->dot3StatsDeferredTransmissions);
2378eb6c4f9Sly 		(knp++)->value.ui64 =
238931dca7dSgs 		    (uint64_t)(pstats->dot3StatsExcessiveCollisions);
2398eb6c4f9Sly 		(knp++)->value.ui64 =
240931dca7dSgs 		    (uint64_t)(pstats->dot3StatsLateCollisions);
241931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCOutUcastPkts);
242931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCOutMulticastPkts);
243931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCOutBroadcastPkts);
244931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCInOctets);
245931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->etherStatsFragments);
246931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCInUcastPkts);
247931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCInMulticastPkts);
248931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->ifHCInBroadcastPkts);
249931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->dot3StatsFCSErrors);
2508eb6c4f9Sly 		(knp++)->value.ui64 =
251931dca7dSgs 		    (uint64_t)(pstats->dot3StatsAlignmentErrors);
2528eb6c4f9Sly 		(knp++)->value.ui64 =
253931dca7dSgs 		    (uint64_t)(pstats->xonPauseFramesReceived);
2548eb6c4f9Sly 		(knp++)->value.ui64 =
255931dca7dSgs 		    (uint64_t)(pstats->xoffPauseFramesReceived);
2568eb6c4f9Sly 		(knp++)->value.ui64 =
257931dca7dSgs 		    (uint64_t)(pstats->macControlFramesReceived);
258931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->xoffStateEntered);
2598eb6c4f9Sly 		(knp++)->value.ui64 =
260931dca7dSgs 		    (uint64_t)(pstats->dot3StatsFrameTooLongs);
261931dca7dSgs 		(knp++)->value.ui64 = (uint64_t)(pstats->etherStatsJabbers);
2628eb6c4f9Sly 		(knp++)->value.ui64 =
263931dca7dSgs 		    (uint64_t)(pstats->etherStatsUndersizePkts);
2648eb6c4f9Sly 	}
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 	return (0);
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate static const bge_ksindex_t bge_chipid[] = {
2707c478bd9Sstevel@tonic-gate 	{ 0,				"asic_rev"		},
2717c478bd9Sstevel@tonic-gate 	{ 1,				"businfo"		},
2727c478bd9Sstevel@tonic-gate 	{ 2,				"command"		},
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	{ 3,				"vendor_id"		},
2757c478bd9Sstevel@tonic-gate 	{ 4,				"device_id"		},
2767c478bd9Sstevel@tonic-gate 	{ 5,				"subsystem_vendor_id"	},
2777c478bd9Sstevel@tonic-gate 	{ 6,				"subsystem_device_id"	},
2787c478bd9Sstevel@tonic-gate 	{ 7,				"revision_id"		},
2797c478bd9Sstevel@tonic-gate 	{ 8,				"cache_line_size"	},
2807c478bd9Sstevel@tonic-gate 	{ 9,				"latency_timer"		},
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	{ 10,				"flags"			},
2837c478bd9Sstevel@tonic-gate 	{ 11,				"chip_type"		},
2847c478bd9Sstevel@tonic-gate 	{ 12,				"mbuf_base"		},
2857c478bd9Sstevel@tonic-gate 	{ 13,				"mbuf_count"		},
2867c478bd9Sstevel@tonic-gate 	{ 14,				"hw_mac_addr"		},
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	{ 15,				"&bus_type"		},
2897c478bd9Sstevel@tonic-gate 	{ 16,				"&bus_speed"		},
2907c478bd9Sstevel@tonic-gate 	{ 17,				"&bus_size"		},
2917c478bd9Sstevel@tonic-gate 	{ 18,				"&supported"		},
2927c478bd9Sstevel@tonic-gate 	{ 19,				"&interface"		},
2937c478bd9Sstevel@tonic-gate 
294087a28d1SDavid Gwynne 	{ 20,				"nvtype"		},
295087a28d1SDavid Gwynne 
296087a28d1SDavid Gwynne 	{ 21,				"asic_rev_prod_id"	},
297087a28d1SDavid Gwynne 
298*87a49193SRobert Mustacchi 	{ -1,				NULL			}
2997c478bd9Sstevel@tonic-gate };
3007c478bd9Sstevel@tonic-gate 
3017c478bd9Sstevel@tonic-gate static void
bge_set_char_kstat(kstat_named_t * knp,const char * s)3027c478bd9Sstevel@tonic-gate bge_set_char_kstat(kstat_named_t *knp, const char *s)
3037c478bd9Sstevel@tonic-gate {
3047c478bd9Sstevel@tonic-gate 	(void) strncpy(knp->value.c, s, sizeof (knp->value.c));
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate static int
bge_chipid_update(kstat_t * ksp,int flag)3087c478bd9Sstevel@tonic-gate bge_chipid_update(kstat_t *ksp, int flag)
3097c478bd9Sstevel@tonic-gate {
3107c478bd9Sstevel@tonic-gate 	bge_t *bgep;
3117c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
3127c478bd9Sstevel@tonic-gate 	uint64_t tmp;
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	if (flag != KSTAT_READ)
3157c478bd9Sstevel@tonic-gate 		return (EACCES);
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 	bgep = ksp->ks_private;
3187c478bd9Sstevel@tonic-gate 	knp = ksp->ks_data;
3197c478bd9Sstevel@tonic-gate 
3207c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.asic_rev;
3217c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.businfo;
3227c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.command;
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.vendor;
3257c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.device;
3267c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.subven;
3277c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.subdev;
3287c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.revision;
3297c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.clsize;
3307c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.latency;
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.flags;
3337c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.chip_label;
3347c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.mbuf_base;
3357c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.mbuf_length;
3367c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chipid.hw_mac_addr;
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	/*
3397c478bd9Sstevel@tonic-gate 	 * Now we interpret some of the above into readable strings
3407c478bd9Sstevel@tonic-gate 	 */
3417c478bd9Sstevel@tonic-gate 	tmp = bgep->chipid.businfo;
3427c478bd9Sstevel@tonic-gate 	bge_set_char_kstat(knp++,
343c56459abSml 	    tmp & PCISTATE_BUS_IS_PCI ? "PCI" : "PCI-X");
3447c478bd9Sstevel@tonic-gate 	bge_set_char_kstat(knp++,
345c56459abSml 	    tmp & PCISTATE_BUS_IS_FAST ? "fast" : "normal");
3467c478bd9Sstevel@tonic-gate 	bge_set_char_kstat(knp++,
347c56459abSml 	    tmp & PCISTATE_BUS_IS_32_BIT ? "32 bit" : "64 bit");
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	tmp = bgep->chipid.flags;
3507c478bd9Sstevel@tonic-gate 	bge_set_char_kstat(knp++,
351c56459abSml 	    tmp & CHIP_FLAG_SUPPORTED ? "yes" : "no");
3527c478bd9Sstevel@tonic-gate 	bge_set_char_kstat(knp++,
353c56459abSml 	    tmp & CHIP_FLAG_SERDES ? "serdes" : "copper");
3547c478bd9Sstevel@tonic-gate 
355087a28d1SDavid Gwynne 	(knp++)->value.ui64 =
356087a28d1SDavid Gwynne 	    ((bgep->chipid.nvtype == BGE_NVTYPE_NONE) ||
357087a28d1SDavid Gwynne 	     (bgep->chipid.nvtype == BGE_NVTYPE_UNKNOWN)) ?
358087a28d1SDavid Gwynne 	    0 : bgep->chipid.nvtype;
359087a28d1SDavid Gwynne 
360087a28d1SDavid Gwynne 	(knp++)->value.ui64 = bgep->chipid.asic_rev_prod_id;
361087a28d1SDavid Gwynne 
3627c478bd9Sstevel@tonic-gate 	return (0);
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate static const bge_ksindex_t bge_driverinfo[] = {
3667c478bd9Sstevel@tonic-gate 	{ 0,				"rx_buff_addr"		},
3677c478bd9Sstevel@tonic-gate 	{ 1,				"tx_buff_addr"		},
3687c478bd9Sstevel@tonic-gate 	{ 2,				"rx_desc_addr"		},
3697c478bd9Sstevel@tonic-gate 	{ 3,				"tx_desc_addr"		},
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 	{ 4,				"tx_desc_free"		},
372931dca7dSgs 	{ 5,				"tx_array"		},
373931dca7dSgs 	{ 6,				"tc_next"		},
374931dca7dSgs 	{ 7,				"tx_next"		},
375931dca7dSgs 	{ 8,				"txfill_next"		},
376931dca7dSgs 	{ 9,				"txpkt_next"		},
377931dca7dSgs 	{ 10,				"tx_bufs"		},
378931dca7dSgs 	{ 11,				"tx_flow"		},
379931dca7dSgs 	{ 12,				"tx_resched_needed"	},
380931dca7dSgs 	{ 13,				"tx_resched"		},
381931dca7dSgs 	{ 14,				"tx_nobuf"		},
382931dca7dSgs 	{ 15,				"tx_nobd"		},
383931dca7dSgs 	{ 16,				"tx_block"		},
384931dca7dSgs 	{ 17,				"tx_alloc_fail"		},
385931dca7dSgs 
386931dca7dSgs 	{ 18,				"watchdog"		},
387931dca7dSgs 	{ 19,				"chip_resets"		},
388931dca7dSgs 	{ 20,				"dma_misses"		},
3895952d588Szh 	{ 21,				"update_misses"		},
390931dca7dSgs 
3915952d588Szh 	{ 22,				"misc_host_config"	},
3925952d588Szh 	{ 23,				"dma_rw_control"	},
3935952d588Szh 	{ 24,				"pci_bus_info"		},
394931dca7dSgs 
3955952d588Szh 	{ 25,				"buff_mgr_status"	},
3965952d588Szh 	{ 26,				"rcv_init_status"	},
3977c478bd9Sstevel@tonic-gate 
398*87a49193SRobert Mustacchi 	{ -1,				NULL			}
3997c478bd9Sstevel@tonic-gate };
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate static int
bge_driverinfo_update(kstat_t * ksp,int flag)4027c478bd9Sstevel@tonic-gate bge_driverinfo_update(kstat_t *ksp, int flag)
4037c478bd9Sstevel@tonic-gate {
4047c478bd9Sstevel@tonic-gate 	bge_t *bgep;
4057c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
4067c478bd9Sstevel@tonic-gate 	ddi_acc_handle_t handle;
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate 	if (flag != KSTAT_READ)
4097c478bd9Sstevel@tonic-gate 		return (EACCES);
4107c478bd9Sstevel@tonic-gate 
4117c478bd9Sstevel@tonic-gate 	bgep = ksp->ks_private;
41200d0963fSdilpreet 	if (bgep->bge_chip_state == BGE_CHIP_FAULT)
41300d0963fSdilpreet 		return (EIO);
41400d0963fSdilpreet 
4157c478bd9Sstevel@tonic-gate 	knp = ksp->ks_data;
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->rx_buff[0].cookie.dmac_laddress;
4187c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->tx_buff[0].cookie.dmac_laddress;
4197c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->rx_desc[0].cookie.dmac_laddress;
4207c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->tx_desc.cookie.dmac_laddress;
4217c478bd9Sstevel@tonic-gate 
4227c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->send[0].tx_free;
423931dca7dSgs 	(knp++)->value.ui64 = bgep->send[0].tx_array;
424931dca7dSgs 	(knp++)->value.ui64 = bgep->send[0].tc_next;
425931dca7dSgs 	(knp++)->value.ui64 = bgep->send[0].tx_next;
426931dca7dSgs 	(knp++)->value.ui64 = bgep->send[0].txfill_next;
427931dca7dSgs 	(knp++)->value.ui64 = bgep->send[0].txpkt_next;
428931dca7dSgs 	(knp++)->value.ui64 = bgep->send[0].txbuf_pop_queue->count +
429931dca7dSgs 	    bgep->send[0].txbuf_push_queue->count;
430931dca7dSgs 	(knp++)->value.ui64 = bgep->send[0].tx_flow;
431931dca7dSgs 	(knp++)->value.ui64 = bgep->tx_resched_needed;
432931dca7dSgs 	(knp++)->value.ui64 = bgep->tx_resched;
433931dca7dSgs 	(knp++)->value.ui64 = bgep->send[0].tx_nobuf;
434931dca7dSgs 	(knp++)->value.ui64 = bgep->send[0].tx_nobd;
435931dca7dSgs 	(knp++)->value.ui64 = bgep->send[0].tx_block;
436931dca7dSgs 	(knp++)->value.ui64 = bgep->send[0].tx_alloc_fail;
437931dca7dSgs 
4387c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->watchdog;
4397c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->chip_resets;
4407c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->missed_dmas;
4415952d588Szh 	(knp++)->value.ui64 = bgep->missed_updates;
4427c478bd9Sstevel@tonic-gate 
4437c478bd9Sstevel@tonic-gate 	/*
4447c478bd9Sstevel@tonic-gate 	 * Hold the mutex while accessing the chip registers
4457c478bd9Sstevel@tonic-gate 	 * just in case the factotum is trying to reset it!
4467c478bd9Sstevel@tonic-gate 	 */
4477c478bd9Sstevel@tonic-gate 	handle = bgep->cfg_handle;
4487c478bd9Sstevel@tonic-gate 	mutex_enter(bgep->genlock);
4497c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = pci_config_get32(handle, PCI_CONF_BGE_MHCR);
4507c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = pci_config_get32(handle, PCI_CONF_BGE_PDRWCR);
4517c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = pci_config_get32(handle, PCI_CONF_BGE_PCISTATE);
45200d0963fSdilpreet 	if (bge_check_acc_handle(bgep, bgep->cfg_handle) != DDI_FM_OK) {
45300d0963fSdilpreet 		ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED);
45400d0963fSdilpreet 		mutex_exit(bgep->genlock);
45500d0963fSdilpreet 		return (EIO);
45600d0963fSdilpreet 	}
4577c478bd9Sstevel@tonic-gate 
4587c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bge_reg_get32(bgep, BUFFER_MANAGER_STATUS_REG);
4597c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bge_reg_get32(bgep, RCV_INITIATOR_STATUS_REG);
46000d0963fSdilpreet 	if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) {
46100d0963fSdilpreet 		ddi_fm_service_impact(bgep->devinfo, DDI_SERVICE_DEGRADED);
46200d0963fSdilpreet 		mutex_exit(bgep->genlock);
46300d0963fSdilpreet 		return (EIO);
46400d0963fSdilpreet 	}
4657c478bd9Sstevel@tonic-gate 	mutex_exit(bgep->genlock);
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 	return (0);
4687c478bd9Sstevel@tonic-gate }
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate static const bge_ksindex_t bge_serdes[] = {
4717c478bd9Sstevel@tonic-gate 	{ 0,				"serdes_status"		},
4727c478bd9Sstevel@tonic-gate 	{ 1,				"serdes_advert"		},
4737c478bd9Sstevel@tonic-gate 	{ 2,				"serdes_lpadv"		},
4747c478bd9Sstevel@tonic-gate 
4757c478bd9Sstevel@tonic-gate 	{ -1,				NULL }
4767c478bd9Sstevel@tonic-gate };
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate static int
bge_serdes_update(kstat_t * ksp,int flag)4797c478bd9Sstevel@tonic-gate bge_serdes_update(kstat_t *ksp, int flag)
4807c478bd9Sstevel@tonic-gate {
4817c478bd9Sstevel@tonic-gate 	bge_t *bgep;
4827c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
4837c478bd9Sstevel@tonic-gate 
4847c478bd9Sstevel@tonic-gate 	if (flag != KSTAT_READ)
4857c478bd9Sstevel@tonic-gate 		return (EACCES);
4867c478bd9Sstevel@tonic-gate 
4877c478bd9Sstevel@tonic-gate 	bgep = ksp->ks_private;
4887c478bd9Sstevel@tonic-gate 	knp = ksp->ks_data;
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->serdes_status;
4917c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->serdes_advert;
4927c478bd9Sstevel@tonic-gate 	(knp++)->value.ui64 = bgep->serdes_lpadv;
4937c478bd9Sstevel@tonic-gate 
4947c478bd9Sstevel@tonic-gate 	return (0);
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate static const bge_ksindex_t bge_phydata[] = {
4987c478bd9Sstevel@tonic-gate 	{ MII_CONTROL,			"mii_control"		},
4997c478bd9Sstevel@tonic-gate 	{ MII_STATUS,			"mii_status"		},
5007c478bd9Sstevel@tonic-gate 	{ MII_PHYIDH,			"phy_identifier"	},
5017c478bd9Sstevel@tonic-gate 	{ MII_AN_ADVERT,		"an_advert"		},
5027c478bd9Sstevel@tonic-gate 	{ MII_AN_LPABLE,		"an_lp_ability"		},
5037c478bd9Sstevel@tonic-gate 	{ MII_AN_EXPANSION,		"an_expansion"		},
504bdb9230aSGarrett D'Amore 	{ MII_AN_NXTPGLP,		"an_lp_nextpage"	},
505bdb9230aSGarrett D'Amore 	{ MII_MSCONTROL,		"gbit_control"		},
506bdb9230aSGarrett D'Amore 	{ MII_MSSTATUS,			"gbit_status"		},
507bdb9230aSGarrett D'Amore 	{ MII_EXTSTATUS,		"ieee_ext_status"	},
5087c478bd9Sstevel@tonic-gate 	{ MII_EXT_CONTROL,		"phy_ext_control"	},
5097c478bd9Sstevel@tonic-gate 	{ MII_EXT_STATUS,		"phy_ext_status"	},
5107c478bd9Sstevel@tonic-gate 	{ MII_RCV_ERR_COUNT,		"receive_error_count"	},
5117c478bd9Sstevel@tonic-gate 	{ MII_FALSE_CARR_COUNT,		"false_carrier_count"	},
5127c478bd9Sstevel@tonic-gate 	{ MII_RCV_NOT_OK_COUNT,		"receiver_not_ok_count"	},
5137c478bd9Sstevel@tonic-gate 	{ MII_AUX_CONTROL,		"aux_control"		},
5147c478bd9Sstevel@tonic-gate 	{ MII_AUX_STATUS,		"aux_status"		},
5157c478bd9Sstevel@tonic-gate 	{ MII_INTR_STATUS,		"intr_status"		},
5167c478bd9Sstevel@tonic-gate 	{ MII_INTR_MASK,		"intr_mask"		},
5177c478bd9Sstevel@tonic-gate 	{ MII_HCD_STATUS,		"hcd_status"		},
518087a28d1SDavid Gwynne 	{ EEE_MODE_REG,			"eee"			},
5197c478bd9Sstevel@tonic-gate 
5207c478bd9Sstevel@tonic-gate 	{ -1,				NULL }
5217c478bd9Sstevel@tonic-gate };
5227c478bd9Sstevel@tonic-gate 
5237c478bd9Sstevel@tonic-gate static int
bge_phydata_update(kstat_t * ksp,int flag)5247c478bd9Sstevel@tonic-gate bge_phydata_update(kstat_t *ksp, int flag)
5257c478bd9Sstevel@tonic-gate {
5267c478bd9Sstevel@tonic-gate 	bge_t *bgep;
5277c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
5287c478bd9Sstevel@tonic-gate 	const bge_ksindex_t *ksip;
5297c478bd9Sstevel@tonic-gate 
5307c478bd9Sstevel@tonic-gate 	if (flag != KSTAT_READ)
5317c478bd9Sstevel@tonic-gate 		return (EACCES);
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 	bgep = ksp->ks_private;
53400d0963fSdilpreet 	if (bgep->bge_chip_state == BGE_CHIP_FAULT)
53500d0963fSdilpreet 		return (EIO);
53600d0963fSdilpreet 
5377c478bd9Sstevel@tonic-gate 	knp = ksp->ks_data;
5387c478bd9Sstevel@tonic-gate 
5397c478bd9Sstevel@tonic-gate 	/*
5407c478bd9Sstevel@tonic-gate 	 * Read the PHY registers & update the kstats ...
5417c478bd9Sstevel@tonic-gate 	 *
5427c478bd9Sstevel@tonic-gate 	 * We need to hold the mutex while performing MII reads, but
5437c478bd9Sstevel@tonic-gate 	 * we don't want to hold it across the entire sequence of reads.
5447c478bd9Sstevel@tonic-gate 	 * So we grab and release it on each iteration, 'cos it doesn't
5457c478bd9Sstevel@tonic-gate 	 * really matter if the kstats are less than 100% consistent ...
5467c478bd9Sstevel@tonic-gate 	 */
5477c478bd9Sstevel@tonic-gate 	for (ksip = bge_phydata; ksip->name != NULL; ++knp, ++ksip) {
5487c478bd9Sstevel@tonic-gate 		mutex_enter(bgep->genlock);
5497c478bd9Sstevel@tonic-gate 		switch (ksip->index) {
5507c478bd9Sstevel@tonic-gate 		case MII_STATUS:
5517c478bd9Sstevel@tonic-gate 			knp->value.ui64 = bgep->phy_gen_status;
5527c478bd9Sstevel@tonic-gate 			break;
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 		case MII_PHYIDH:
5557c478bd9Sstevel@tonic-gate 			knp->value.ui64 = bge_mii_get16(bgep, MII_PHYIDH);
5567c478bd9Sstevel@tonic-gate 			knp->value.ui64 <<= 16;
5577c478bd9Sstevel@tonic-gate 			knp->value.ui64 |= bge_mii_get16(bgep, MII_PHYIDL);
5587c478bd9Sstevel@tonic-gate 			break;
5597c478bd9Sstevel@tonic-gate 
560087a28d1SDavid Gwynne 		case EEE_MODE_REG:
561087a28d1SDavid Gwynne 			knp->value.ui64 = 0;
562087a28d1SDavid Gwynne 			if (bgep->link_state == LINK_STATE_UP)
563087a28d1SDavid Gwynne 			{
564087a28d1SDavid Gwynne 				knp->value.ui64 =
565087a28d1SDavid Gwynne 				    (bge_reg_get32(bgep, EEE_MODE_REG) & 0x80) ?
566087a28d1SDavid Gwynne 				        1 : 0;
567087a28d1SDavid Gwynne 			}
568087a28d1SDavid Gwynne 			break;
569087a28d1SDavid Gwynne 
5707c478bd9Sstevel@tonic-gate 		default:
5717c478bd9Sstevel@tonic-gate 			knp->value.ui64 = bge_mii_get16(bgep, ksip->index);
5727c478bd9Sstevel@tonic-gate 			break;
5737c478bd9Sstevel@tonic-gate 		}
57400d0963fSdilpreet 		if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) {
57500d0963fSdilpreet 			ddi_fm_service_impact(bgep->devinfo,
57600d0963fSdilpreet 			    DDI_SERVICE_DEGRADED);
57700d0963fSdilpreet 			mutex_exit(bgep->genlock);
57800d0963fSdilpreet 			return (EIO);
57900d0963fSdilpreet 		}
5807c478bd9Sstevel@tonic-gate 		mutex_exit(bgep->genlock);
5817c478bd9Sstevel@tonic-gate 	}
5827c478bd9Sstevel@tonic-gate 
5837c478bd9Sstevel@tonic-gate 	return (0);
5847c478bd9Sstevel@tonic-gate }
5857c478bd9Sstevel@tonic-gate 
5867c478bd9Sstevel@tonic-gate static kstat_t *
bge_setup_named_kstat(bge_t * bgep,int instance,char * name,const bge_ksindex_t * ksip,size_t size,int (* update)(kstat_t *,int))5877c478bd9Sstevel@tonic-gate bge_setup_named_kstat(bge_t *bgep, int instance, char *name,
5887c478bd9Sstevel@tonic-gate 	const bge_ksindex_t *ksip, size_t size, int (*update)(kstat_t *, int))
5897c478bd9Sstevel@tonic-gate {
5907c478bd9Sstevel@tonic-gate 	kstat_t *ksp;
5917c478bd9Sstevel@tonic-gate 	kstat_named_t *knp;
5927c478bd9Sstevel@tonic-gate 	char *np;
5937c478bd9Sstevel@tonic-gate 	int type;
5947c478bd9Sstevel@tonic-gate 
5957c478bd9Sstevel@tonic-gate 	size /= sizeof (bge_ksindex_t);
5967c478bd9Sstevel@tonic-gate 	ksp = kstat_create(BGE_DRIVER_NAME, instance, name, "net",
597087a28d1SDavid Gwynne 	    KSTAT_TYPE_NAMED, size-1, 0);
5987c478bd9Sstevel@tonic-gate 	if (ksp == NULL)
5997c478bd9Sstevel@tonic-gate 		return (NULL);
6007c478bd9Sstevel@tonic-gate 
6017c478bd9Sstevel@tonic-gate 	ksp->ks_private = bgep;
6027c478bd9Sstevel@tonic-gate 	ksp->ks_update = update;
6037c478bd9Sstevel@tonic-gate 	for (knp = ksp->ks_data; (np = ksip->name) != NULL; ++knp, ++ksip) {
6047c478bd9Sstevel@tonic-gate 		switch (*np) {
6057c478bd9Sstevel@tonic-gate 		default:
6067c478bd9Sstevel@tonic-gate 			type = KSTAT_DATA_UINT64;
6077c478bd9Sstevel@tonic-gate 			break;
6087c478bd9Sstevel@tonic-gate 		case '%':
6097c478bd9Sstevel@tonic-gate 			np += 1;
6107c478bd9Sstevel@tonic-gate 			type = KSTAT_DATA_UINT32;
6117c478bd9Sstevel@tonic-gate 			break;
6127c478bd9Sstevel@tonic-gate 		case '$':
6137c478bd9Sstevel@tonic-gate 			np += 1;
6147c478bd9Sstevel@tonic-gate 			type = KSTAT_DATA_STRING;
6157c478bd9Sstevel@tonic-gate 			break;
6167c478bd9Sstevel@tonic-gate 		case '&':
6177c478bd9Sstevel@tonic-gate 			np += 1;
6187c478bd9Sstevel@tonic-gate 			type = KSTAT_DATA_CHAR;
6197c478bd9Sstevel@tonic-gate 			break;
6207c478bd9Sstevel@tonic-gate 		}
6217c478bd9Sstevel@tonic-gate 		kstat_named_init(knp, np, type);
6227c478bd9Sstevel@tonic-gate 	}
6237c478bd9Sstevel@tonic-gate 	kstat_install(ksp);
6247c478bd9Sstevel@tonic-gate 
6257c478bd9Sstevel@tonic-gate 	return (ksp);
6267c478bd9Sstevel@tonic-gate }
6277c478bd9Sstevel@tonic-gate 
6287c478bd9Sstevel@tonic-gate void
bge_init_kstats(bge_t * bgep,int instance)6297c478bd9Sstevel@tonic-gate bge_init_kstats(bge_t *bgep, int instance)
6307c478bd9Sstevel@tonic-gate {
6317c478bd9Sstevel@tonic-gate 	kstat_t *ksp;
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate 	BGE_TRACE(("bge_init_kstats($%p, %d)", (void *)bgep, instance));
6347c478bd9Sstevel@tonic-gate 
6358eb6c4f9Sly 	if (bgep->chipid.statistic_type == BGE_STAT_BLK) {
6368eb6c4f9Sly 		DMA_ZERO(bgep->statistics);
6378eb6c4f9Sly 		bgep->bge_kstats[BGE_KSTAT_RAW] = ksp =
638c56459abSml 		    kstat_create(BGE_DRIVER_NAME, instance,
639c56459abSml 		    "raw_statistics", "net", KSTAT_TYPE_RAW,
640c56459abSml 		    sizeof (bge_statistics_t), KSTAT_FLAG_VIRTUAL);
6418eb6c4f9Sly 		if (ksp != NULL) {
6428eb6c4f9Sly 			ksp->ks_data = DMA_VPTR(bgep->statistics);
6438eb6c4f9Sly 			kstat_install(ksp);
6448eb6c4f9Sly 		}
6457c478bd9Sstevel@tonic-gate 
6468eb6c4f9Sly 		bgep->bge_kstats[BGE_KSTAT_STATS] = bge_setup_named_kstat(bgep,
647c56459abSml 		    instance, "statistics", bge_statistics,
648c56459abSml 		    sizeof (bge_statistics), bge_statistics_update);
6498eb6c4f9Sly 	} else {
6508eb6c4f9Sly 		bgep->bge_kstats[BGE_KSTAT_STATS] = bge_setup_named_kstat(bgep,
651c56459abSml 		    instance, "statistics", bge_stat_val,
652c56459abSml 		    sizeof (bge_stat_val), bge_statistics_update);
6538eb6c4f9Sly 	}
6547c478bd9Sstevel@tonic-gate 
6557c478bd9Sstevel@tonic-gate 	bgep->bge_kstats[BGE_KSTAT_CHIPID] = bge_setup_named_kstat(bgep,
656c56459abSml 	    instance, "chipid", bge_chipid,
657c56459abSml 	    sizeof (bge_chipid), bge_chipid_update);
6587c478bd9Sstevel@tonic-gate 
6597c478bd9Sstevel@tonic-gate 	bgep->bge_kstats[BGE_KSTAT_DRIVER] = bge_setup_named_kstat(bgep,
660c56459abSml 	    instance, "driverinfo", bge_driverinfo,
661c56459abSml 	    sizeof (bge_driverinfo), bge_driverinfo_update);
6627c478bd9Sstevel@tonic-gate 
6637c478bd9Sstevel@tonic-gate 	if (bgep->chipid.flags & CHIP_FLAG_SERDES)
6647c478bd9Sstevel@tonic-gate 		bgep->bge_kstats[BGE_KSTAT_PHYS] = bge_setup_named_kstat(bgep,
665c56459abSml 		    instance, "serdes", bge_serdes,
666c56459abSml 		    sizeof (bge_serdes), bge_serdes_update);
6677c478bd9Sstevel@tonic-gate 	else
6687c478bd9Sstevel@tonic-gate 		bgep->bge_kstats[BGE_KSTAT_PHYS] = bge_setup_named_kstat(bgep,
669c56459abSml 		    instance, "phydata", bge_phydata,
670c56459abSml 		    sizeof (bge_phydata), bge_phydata_update);
6717c478bd9Sstevel@tonic-gate 
6727c478bd9Sstevel@tonic-gate }
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate void
bge_fini_kstats(bge_t * bgep)6757c478bd9Sstevel@tonic-gate bge_fini_kstats(bge_t *bgep)
6767c478bd9Sstevel@tonic-gate {
6777c478bd9Sstevel@tonic-gate 	int i;
6787c478bd9Sstevel@tonic-gate 
6797c478bd9Sstevel@tonic-gate 	BGE_TRACE(("bge_fini_kstats($%p)", (void *)bgep));
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate 	for (i = BGE_KSTAT_COUNT; --i >= 0; )
6827c478bd9Sstevel@tonic-gate 		if (bgep->bge_kstats[i] != NULL)
6837c478bd9Sstevel@tonic-gate 			kstat_delete(bgep->bge_kstats[i]);
6847c478bd9Sstevel@tonic-gate }
6857c478bd9Sstevel@tonic-gate 
686ba2e4443Sseb int
bge_m_stat(void * arg,uint_t stat,uint64_t * val)687ba2e4443Sseb bge_m_stat(void *arg, uint_t stat, uint64_t *val)
6887c478bd9Sstevel@tonic-gate {
6897c478bd9Sstevel@tonic-gate 	bge_t *bgep = arg;
6908eb6c4f9Sly 	bge_statistics_t *bstp;
691931dca7dSgs 	bge_statistics_reg_t *pstats;
6927c478bd9Sstevel@tonic-gate 
693087a28d1SDavid Gwynne 	if (bgep->bge_chip_state != BGE_CHIP_RUNNING) {
694ba2e4443Sseb 		return (EINVAL);
695ba2e4443Sseb 	}
696ba2e4443Sseb 
6978eb6c4f9Sly 	if (bgep->chipid.statistic_type == BGE_STAT_BLK)
6988eb6c4f9Sly 		bstp = DMA_VPTR(bgep->statistics);
6998eb6c4f9Sly 	else {
700931dca7dSgs 		pstats = bgep->pstats;
701931dca7dSgs 		pstats->ifHCOutOctets +=
702931dca7dSgs 		    bge_reg_get32(bgep, STAT_IFHCOUT_OCTETS_REG);
703931dca7dSgs 		pstats->etherStatsCollisions +=
704931dca7dSgs 		    bge_reg_get32(bgep, STAT_ETHER_COLLIS_REG);
705931dca7dSgs 		pstats->outXonSent +=
706931dca7dSgs 		    bge_reg_get32(bgep, STAT_OUTXON_SENT_REG);
707931dca7dSgs 		pstats->outXoffSent +=
708931dca7dSgs 		    bge_reg_get32(bgep, STAT_OUTXOFF_SENT_REG);
709931dca7dSgs 		pstats->dot3StatsInternalMacTransmitErrors +=
710931dca7dSgs 		    bge_reg_get32(bgep, STAT_DOT3_INTMACTX_ERR_REG);
711931dca7dSgs 		pstats->dot3StatsSingleCollisionFrames +=
712931dca7dSgs 		    bge_reg_get32(bgep, STAT_DOT3_SCOLLI_FRAME_REG);
713931dca7dSgs 		pstats->dot3StatsMultipleCollisionFrames +=
714931dca7dSgs 		    bge_reg_get32(bgep, STAT_DOT3_MCOLLI_FRAME_REG);
715931dca7dSgs 		pstats->dot3StatsDeferredTransmissions +=
716931dca7dSgs 		    bge_reg_get32(bgep, STAT_DOT3_DEFERED_TX_REG);
717931dca7dSgs 		pstats->dot3StatsExcessiveCollisions +=
718931dca7dSgs 		    bge_reg_get32(bgep, STAT_DOT3_EXCE_COLLI_REG);
719931dca7dSgs 		pstats->dot3StatsLateCollisions +=
720931dca7dSgs 		    bge_reg_get32(bgep, STAT_DOT3_LATE_COLLI_REG);
721931dca7dSgs 		pstats->ifHCOutUcastPkts +=
722931dca7dSgs 		    bge_reg_get32(bgep, STAT_IFHCOUT_UPKGS_REG);
723931dca7dSgs 		pstats->ifHCOutMulticastPkts +=
724931dca7dSgs 		    bge_reg_get32(bgep, STAT_IFHCOUT_MPKGS_REG);
725931dca7dSgs 		pstats->ifHCOutBroadcastPkts +=
726931dca7dSgs 		    bge_reg_get32(bgep, STAT_IFHCOUT_BPKGS_REG);
727931dca7dSgs 		pstats->ifHCInOctets +=
728931dca7dSgs 		    bge_reg_get32(bgep, STAT_IFHCIN_OCTETS_REG);
729931dca7dSgs 		pstats->etherStatsFragments +=
730931dca7dSgs 		    bge_reg_get32(bgep, STAT_ETHER_FRAGMENT_REG);
731931dca7dSgs 		pstats->ifHCInUcastPkts +=
732931dca7dSgs 		    bge_reg_get32(bgep, STAT_IFHCIN_UPKGS_REG);
733931dca7dSgs 		pstats->ifHCInMulticastPkts +=
734931dca7dSgs 		    bge_reg_get32(bgep, STAT_IFHCIN_MPKGS_REG);
735931dca7dSgs 		pstats->ifHCInBroadcastPkts +=
736931dca7dSgs 		    bge_reg_get32(bgep, STAT_IFHCIN_BPKGS_REG);
737931dca7dSgs 		pstats->dot3StatsFCSErrors +=
738931dca7dSgs 		    bge_reg_get32(bgep, STAT_DOT3_FCS_ERR_REG);
739931dca7dSgs 		pstats->dot3StatsAlignmentErrors +=
740931dca7dSgs 		    bge_reg_get32(bgep, STAT_DOT3_ALIGN_ERR_REG);
741931dca7dSgs 		pstats->xonPauseFramesReceived +=
742931dca7dSgs 		    bge_reg_get32(bgep, STAT_XON_PAUSE_RX_REG);
743931dca7dSgs 		pstats->xoffPauseFramesReceived +=
744931dca7dSgs 		    bge_reg_get32(bgep, STAT_XOFF_PAUSE_RX_REG);
745931dca7dSgs 		pstats->macControlFramesReceived +=
746931dca7dSgs 		    bge_reg_get32(bgep, STAT_MAC_CTRL_RX_REG);
747931dca7dSgs 		pstats->xoffStateEntered +=
748931dca7dSgs 		    bge_reg_get32(bgep, STAT_XOFF_STATE_ENTER_REG);
749931dca7dSgs 		pstats->dot3StatsFrameTooLongs +=
750931dca7dSgs 		    bge_reg_get32(bgep, STAT_DOT3_FRAME_TOOLONG_REG);
751931dca7dSgs 		pstats->etherStatsJabbers +=
752931dca7dSgs 		    bge_reg_get32(bgep, STAT_ETHER_JABBERS_REG);
753931dca7dSgs 		pstats->etherStatsUndersizePkts +=
754931dca7dSgs 		    bge_reg_get32(bgep, STAT_ETHER_UNDERSIZE_REG);
755f724721bSzh 		mutex_enter(bgep->genlock);
75600d0963fSdilpreet 		if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) {
75700d0963fSdilpreet 			ddi_fm_service_impact(bgep->devinfo,
75800d0963fSdilpreet 			    DDI_SERVICE_UNAFFECTED);
7598eb6c4f9Sly 		}
760f724721bSzh 		mutex_exit(bgep->genlock);
76100d0963fSdilpreet 	}
7628eb6c4f9Sly 
7637c478bd9Sstevel@tonic-gate 	switch (stat) {
7647c478bd9Sstevel@tonic-gate 	case MAC_STAT_IFSPEED:
765087a28d1SDavid Gwynne 		*val = (bgep->link_state != LINK_STATE_UNKNOWN) ?
766087a28d1SDavid Gwynne 		           (bgep->param_link_speed * 1000000ull) : 0;
7677c478bd9Sstevel@tonic-gate 		break;
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate 	case MAC_STAT_MULTIRCV:
7708eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
771ba2e4443Sseb 			*val = bstp->s.ifHCInMulticastPkts;
7728eb6c4f9Sly 		else
773931dca7dSgs 			*val = pstats->ifHCInMulticastPkts;
7747c478bd9Sstevel@tonic-gate 		break;
7757c478bd9Sstevel@tonic-gate 
7767c478bd9Sstevel@tonic-gate 	case MAC_STAT_BRDCSTRCV:
7778eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
778ba2e4443Sseb 			*val = bstp->s.ifHCInBroadcastPkts;
7798eb6c4f9Sly 		else
780931dca7dSgs 			*val = pstats->ifHCInBroadcastPkts;
7817c478bd9Sstevel@tonic-gate 		break;
7827c478bd9Sstevel@tonic-gate 
7837c478bd9Sstevel@tonic-gate 	case MAC_STAT_MULTIXMT:
7848eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
785ba2e4443Sseb 			*val = bstp->s.ifHCOutMulticastPkts;
7868eb6c4f9Sly 		else
787931dca7dSgs 			*val = pstats->ifHCOutMulticastPkts;
7887c478bd9Sstevel@tonic-gate 		break;
7897c478bd9Sstevel@tonic-gate 
7907c478bd9Sstevel@tonic-gate 	case MAC_STAT_BRDCSTXMT:
7918eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
792ba2e4443Sseb 			*val = bstp->s.ifHCOutBroadcastPkts;
7938eb6c4f9Sly 		else
794931dca7dSgs 			*val = pstats->ifHCOutBroadcastPkts;
7957c478bd9Sstevel@tonic-gate 		break;
7967c478bd9Sstevel@tonic-gate 
7977c478bd9Sstevel@tonic-gate 	case MAC_STAT_NORCVBUF:
7988eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
799ba2e4443Sseb 			*val = bstp->s.ifInDiscards;
8008eb6c4f9Sly 		else
801ba2e4443Sseb 			*val = 0;
8027c478bd9Sstevel@tonic-gate 		break;
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate 	case MAC_STAT_IERRORS:
805ba2e4443Sseb 		if (bgep->chipid.statistic_type == BGE_STAT_BLK) {
806ba2e4443Sseb 			*val = bstp->s.dot3StatsFCSErrors +
807931dca7dSgs 			    bstp->s.dot3StatsAlignmentErrors +
808931dca7dSgs 			    bstp->s.dot3StatsFrameTooLongs +
809931dca7dSgs 			    bstp->s.etherStatsUndersizePkts +
810931dca7dSgs 			    bstp->s.etherStatsJabbers;
811ba2e4443Sseb 		} else {
812931dca7dSgs 			*val = pstats->dot3StatsFCSErrors +
813931dca7dSgs 			    pstats->dot3StatsAlignmentErrors +
814931dca7dSgs 			    pstats->dot3StatsFrameTooLongs +
815931dca7dSgs 			    pstats->etherStatsUndersizePkts +
816931dca7dSgs 			    pstats->etherStatsJabbers;
817ba2e4443Sseb 		}
8187c478bd9Sstevel@tonic-gate 		break;
8197c478bd9Sstevel@tonic-gate 
8207c478bd9Sstevel@tonic-gate 	case MAC_STAT_NOXMTBUF:
8218eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
822ba2e4443Sseb 			*val = bstp->s.ifOutDiscards;
8238eb6c4f9Sly 		else
824ba2e4443Sseb 			*val = 0;
8257c478bd9Sstevel@tonic-gate 		break;
8267c478bd9Sstevel@tonic-gate 
8277c478bd9Sstevel@tonic-gate 	case MAC_STAT_OERRORS:
8288eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
829ba2e4443Sseb 			*val = bstp->s.ifOutDiscards;
8308eb6c4f9Sly 		else
831ba2e4443Sseb 			*val = 0;
8327c478bd9Sstevel@tonic-gate 		break;
8337c478bd9Sstevel@tonic-gate 
8347c478bd9Sstevel@tonic-gate 	case MAC_STAT_COLLISIONS:
8358eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
836ba2e4443Sseb 			*val = bstp->s.etherStatsCollisions;
8378eb6c4f9Sly 		else
838931dca7dSgs 			*val = pstats->etherStatsCollisions;
8397c478bd9Sstevel@tonic-gate 		break;
8407c478bd9Sstevel@tonic-gate 
8417c478bd9Sstevel@tonic-gate 	case MAC_STAT_RBYTES:
8428eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
843ba2e4443Sseb 			*val = bstp->s.ifHCInOctets;
8448eb6c4f9Sly 		else
845931dca7dSgs 			*val = pstats->ifHCInOctets;
8467c478bd9Sstevel@tonic-gate 		break;
8477c478bd9Sstevel@tonic-gate 
8487c478bd9Sstevel@tonic-gate 	case MAC_STAT_IPACKETS:
8498eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
850ba2e4443Sseb 			*val = bstp->s.ifHCInUcastPkts +
851ba2e4443Sseb 			    bstp->s.ifHCInMulticastPkts +
852ba2e4443Sseb 			    bstp->s.ifHCInBroadcastPkts;
8538eb6c4f9Sly 		else
854931dca7dSgs 			*val = pstats->ifHCInUcastPkts +
855931dca7dSgs 			    pstats->ifHCInMulticastPkts +
856931dca7dSgs 			    pstats->ifHCInBroadcastPkts;
8577c478bd9Sstevel@tonic-gate 		break;
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate 	case MAC_STAT_OBYTES:
8608eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
861ba2e4443Sseb 			*val = bstp->s.ifHCOutOctets;
8628eb6c4f9Sly 		else
863931dca7dSgs 			*val = pstats->ifHCOutOctets;
8647c478bd9Sstevel@tonic-gate 		break;
8657c478bd9Sstevel@tonic-gate 
8667c478bd9Sstevel@tonic-gate 	case MAC_STAT_OPACKETS:
8678eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
868ba2e4443Sseb 			*val = bstp->s.ifHCOutUcastPkts +
869ba2e4443Sseb 			    bstp->s.ifHCOutMulticastPkts +
870ba2e4443Sseb 			    bstp->s.ifHCOutBroadcastPkts;
8718eb6c4f9Sly 		else
872931dca7dSgs 			*val = pstats->ifHCOutUcastPkts +
873931dca7dSgs 			    pstats->ifHCOutMulticastPkts +
874931dca7dSgs 			    pstats->ifHCOutBroadcastPkts;
8757c478bd9Sstevel@tonic-gate 		break;
8767c478bd9Sstevel@tonic-gate 
877ba2e4443Sseb 	case ETHER_STAT_ALIGN_ERRORS:
8788eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
879ba2e4443Sseb 			*val = bstp->s.dot3StatsAlignmentErrors;
8808eb6c4f9Sly 		else
881931dca7dSgs 			*val = pstats->dot3StatsAlignmentErrors;
8827c478bd9Sstevel@tonic-gate 		break;
8837c478bd9Sstevel@tonic-gate 
884ba2e4443Sseb 	case ETHER_STAT_FCS_ERRORS:
8858eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
886ba2e4443Sseb 			*val = bstp->s.dot3StatsFCSErrors;
8878eb6c4f9Sly 		else
888931dca7dSgs 			*val = pstats->dot3StatsFCSErrors;
8897c478bd9Sstevel@tonic-gate 		break;
8907c478bd9Sstevel@tonic-gate 
891ba2e4443Sseb 	case ETHER_STAT_FIRST_COLLISIONS:
8928eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
893ba2e4443Sseb 			*val = bstp->s.dot3StatsSingleCollisionFrames;
8948eb6c4f9Sly 		else
895931dca7dSgs 			*val = pstats->dot3StatsSingleCollisionFrames;
8967c478bd9Sstevel@tonic-gate 		break;
8977c478bd9Sstevel@tonic-gate 
898ba2e4443Sseb 	case ETHER_STAT_MULTI_COLLISIONS:
8998eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
900ba2e4443Sseb 			*val = bstp->s.dot3StatsMultipleCollisionFrames;
9018eb6c4f9Sly 		else
902931dca7dSgs 			*val = pstats->dot3StatsMultipleCollisionFrames;
9037c478bd9Sstevel@tonic-gate 		break;
9047c478bd9Sstevel@tonic-gate 
905ba2e4443Sseb 	case ETHER_STAT_DEFER_XMTS:
9068eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
907ba2e4443Sseb 			*val = bstp->s.dot3StatsDeferredTransmissions;
9088eb6c4f9Sly 		else
909931dca7dSgs 			*val = pstats->dot3StatsDeferredTransmissions;
9107c478bd9Sstevel@tonic-gate 		break;
9117c478bd9Sstevel@tonic-gate 
912ba2e4443Sseb 	case ETHER_STAT_TX_LATE_COLLISIONS:
9138eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
914ba2e4443Sseb 			*val = bstp->s.dot3StatsLateCollisions;
9158eb6c4f9Sly 		else
916931dca7dSgs 			*val = pstats->dot3StatsLateCollisions;
9177c478bd9Sstevel@tonic-gate 		break;
9187c478bd9Sstevel@tonic-gate 
919ba2e4443Sseb 	case ETHER_STAT_EX_COLLISIONS:
9208eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
921ba2e4443Sseb 			*val = bstp->s.dot3StatsExcessiveCollisions;
9228eb6c4f9Sly 		else
923931dca7dSgs 			*val = pstats->dot3StatsExcessiveCollisions;
9247c478bd9Sstevel@tonic-gate 		break;
9257c478bd9Sstevel@tonic-gate 
926ba2e4443Sseb 	case ETHER_STAT_MACXMT_ERRORS:
9278eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
928ba2e4443Sseb 			*val = bstp->s.dot3StatsInternalMacTransmitErrors;
9298eb6c4f9Sly 		else
930931dca7dSgs 			*val = bgep->pstats->dot3StatsInternalMacTransmitErrors;
9317c478bd9Sstevel@tonic-gate 		break;
9327c478bd9Sstevel@tonic-gate 
933ba2e4443Sseb 	case ETHER_STAT_CARRIER_ERRORS:
9348eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
935ba2e4443Sseb 			*val = bstp->s.dot3StatsCarrierSenseErrors;
9368eb6c4f9Sly 		else
937ba2e4443Sseb 			*val = 0;
9387c478bd9Sstevel@tonic-gate 		break;
9397c478bd9Sstevel@tonic-gate 
940ba2e4443Sseb 	case ETHER_STAT_TOOLONG_ERRORS:
9418eb6c4f9Sly 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
942ba2e4443Sseb 			*val = bstp->s.dot3StatsFrameTooLongs;
9438eb6c4f9Sly 		else
944931dca7dSgs 			*val = pstats->dot3StatsFrameTooLongs;
9457c478bd9Sstevel@tonic-gate 		break;
9467c478bd9Sstevel@tonic-gate 
947087a28d1SDavid Gwynne #if (MAC_VERSION > 1)
9489b14cf1dSgd 	case ETHER_STAT_TOOSHORT_ERRORS:
9499b14cf1dSgd 		if (bgep->chipid.statistic_type == BGE_STAT_BLK)
9509b14cf1dSgd 			*val = bstp->s.etherStatsUndersizePkts;
9519b14cf1dSgd 		else
9529b14cf1dSgd 			*val = pstats->etherStatsUndersizePkts;
9539b14cf1dSgd 		break;
954087a28d1SDavid Gwynne #endif
9559b14cf1dSgd 
956ba2e4443Sseb 	case ETHER_STAT_XCVR_ADDR:
957ba2e4443Sseb 		*val = bgep->phy_mii_addr;
9587c478bd9Sstevel@tonic-gate 		break;
9597c478bd9Sstevel@tonic-gate 
960ba2e4443Sseb 	case ETHER_STAT_XCVR_ID:
961f724721bSzh 		mutex_enter(bgep->genlock);
962ba2e4443Sseb 		*val = bge_mii_get16(bgep, MII_PHYIDH);
963ba2e4443Sseb 		*val <<= 16;
964ba2e4443Sseb 		*val |= bge_mii_get16(bgep, MII_PHYIDL);
96500d0963fSdilpreet 		if (bge_check_acc_handle(bgep, bgep->io_handle) != DDI_FM_OK) {
96600d0963fSdilpreet 			ddi_fm_service_impact(bgep->devinfo,
96700d0963fSdilpreet 			    DDI_SERVICE_UNAFFECTED);
96800d0963fSdilpreet 		}
969f724721bSzh 		mutex_exit(bgep->genlock);
9707c478bd9Sstevel@tonic-gate 		break;
9717c478bd9Sstevel@tonic-gate 
972ba2e4443Sseb 	case ETHER_STAT_XCVR_INUSE:
973*87a49193SRobert Mustacchi 		*val = (uint64_t)bge_phys_media(bgep);
9747c478bd9Sstevel@tonic-gate 		break;
9757c478bd9Sstevel@tonic-gate 
976ba2e4443Sseb 	case ETHER_STAT_CAP_1000FDX:
977ba2e4443Sseb 		*val = 1;
9787c478bd9Sstevel@tonic-gate 		break;
9797c478bd9Sstevel@tonic-gate 
980ba2e4443Sseb 	case ETHER_STAT_CAP_1000HDX:
981ba2e4443Sseb 		*val = 1;
9827c478bd9Sstevel@tonic-gate 		break;
9837c478bd9Sstevel@tonic-gate 
984ba2e4443Sseb 	case ETHER_STAT_CAP_100FDX:
985dca582a1Sgh 		if (bgep->chipid.flags & CHIP_FLAG_SERDES)
986dca582a1Sgh 			*val = 0;
987dca582a1Sgh 		else
988dca582a1Sgh 			*val = 1;
9897c478bd9Sstevel@tonic-gate 		break;
9907c478bd9Sstevel@tonic-gate 
991ba2e4443Sseb 	case ETHER_STAT_CAP_100HDX:
992dca582a1Sgh 		if (bgep->chipid.flags & CHIP_FLAG_SERDES)
993dca582a1Sgh 			*val = 0;
994dca582a1Sgh 		else
995dca582a1Sgh 			*val = 1;
9967c478bd9Sstevel@tonic-gate 		break;
9977c478bd9Sstevel@tonic-gate 
998ba2e4443Sseb 	case ETHER_STAT_CAP_10FDX:
999dca582a1Sgh 		if (bgep->chipid.flags & CHIP_FLAG_SERDES)
1000dca582a1Sgh 			*val = 0;
1001dca582a1Sgh 		else
1002dca582a1Sgh 			*val = 1;
10037c478bd9Sstevel@tonic-gate 		break;
10047c478bd9Sstevel@tonic-gate 
1005ba2e4443Sseb 	case ETHER_STAT_CAP_10HDX:
1006dca582a1Sgh 		if (bgep->chipid.flags & CHIP_FLAG_SERDES)
1007dca582a1Sgh 			*val = 0;
1008dca582a1Sgh 		else
1009dca582a1Sgh 			*val = 1;
10107c478bd9Sstevel@tonic-gate 		break;
10117c478bd9Sstevel@tonic-gate 
1012ba2e4443Sseb 	case ETHER_STAT_CAP_ASMPAUSE:
1013ba2e4443Sseb 		*val = 1;
10147c478bd9Sstevel@tonic-gate 		break;
10157c478bd9Sstevel@tonic-gate 
1016ba2e4443Sseb 	case ETHER_STAT_CAP_PAUSE:
1017ba2e4443Sseb 		*val = 1;
10187c478bd9Sstevel@tonic-gate 		break;
10197c478bd9Sstevel@tonic-gate 
1020ba2e4443Sseb 	case ETHER_STAT_CAP_AUTONEG:
1021ba2e4443Sseb 		*val = 1;
10227c478bd9Sstevel@tonic-gate 		break;
10237c478bd9Sstevel@tonic-gate 
1024087a28d1SDavid Gwynne #if (MAC_VERSION > 1)
10259b14cf1dSgd 	case ETHER_STAT_CAP_REMFAULT:
10269b14cf1dSgd 		*val = 1;
10279b14cf1dSgd 		break;
1028087a28d1SDavid Gwynne #endif
10299b14cf1dSgd 
1030ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_1000FDX:
1031ba2e4443Sseb 		*val = bgep->param_adv_1000fdx;
10327c478bd9Sstevel@tonic-gate 		break;
10337c478bd9Sstevel@tonic-gate 
1034ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_1000HDX:
1035ba2e4443Sseb 		*val = bgep->param_adv_1000hdx;
10367c478bd9Sstevel@tonic-gate 		break;
10377c478bd9Sstevel@tonic-gate 
1038ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_100FDX:
1039ba2e4443Sseb 		*val = bgep->param_adv_100fdx;
10407c478bd9Sstevel@tonic-gate 		break;
10417c478bd9Sstevel@tonic-gate 
1042ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_100HDX:
1043ba2e4443Sseb 		*val = bgep->param_adv_100hdx;
10447c478bd9Sstevel@tonic-gate 		break;
10457c478bd9Sstevel@tonic-gate 
1046ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_10FDX:
1047ba2e4443Sseb 		*val = bgep->param_adv_10fdx;
10487c478bd9Sstevel@tonic-gate 		break;
10497c478bd9Sstevel@tonic-gate 
1050ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_10HDX:
1051ba2e4443Sseb 		*val = bgep->param_adv_10hdx;
10527c478bd9Sstevel@tonic-gate 		break;
10537c478bd9Sstevel@tonic-gate 
1054ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_ASMPAUSE:
1055ba2e4443Sseb 		*val = bgep->param_adv_asym_pause;
10567c478bd9Sstevel@tonic-gate 		break;
10577c478bd9Sstevel@tonic-gate 
1058ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_PAUSE:
1059ba2e4443Sseb 		*val = bgep->param_adv_pause;
10607c478bd9Sstevel@tonic-gate 		break;
10617c478bd9Sstevel@tonic-gate 
1062ba2e4443Sseb 	case ETHER_STAT_ADV_CAP_AUTONEG:
1063ba2e4443Sseb 		*val = bgep->param_adv_autoneg;
10647c478bd9Sstevel@tonic-gate 		break;
10657c478bd9Sstevel@tonic-gate 
1066087a28d1SDavid Gwynne #if (MAC_VERSION > 1)
10679b14cf1dSgd 	case ETHER_STAT_ADV_REMFAULT:
1068dca582a1Sgh 		if (bgep->chipid.flags & CHIP_FLAG_SERDES)
1069dca582a1Sgh 			*val = 0;
1070dca582a1Sgh 		else {
1071dca582a1Sgh 			mutex_enter(bgep->genlock);
1072dca582a1Sgh 			*val = bge_mii_get16(bgep, MII_AN_ADVERT) &
1073dca582a1Sgh 			    MII_AN_ADVERT_REMFAULT ? 1 : 0;
1074dca582a1Sgh 			if (bge_check_acc_handle(bgep, bgep->io_handle) !=
1075dca582a1Sgh 			    DDI_FM_OK) {
1076dca582a1Sgh 				ddi_fm_service_impact(bgep->devinfo,
1077dca582a1Sgh 				    DDI_SERVICE_UNAFFECTED);
1078dca582a1Sgh 			}
1079dca582a1Sgh 			mutex_exit(bgep->genlock);
10809b14cf1dSgd 		}
10819b14cf1dSgd 		break;
1082087a28d1SDavid Gwynne #endif
10839b14cf1dSgd 
1084ba2e4443Sseb 	case ETHER_STAT_LP_CAP_1000FDX:
1085ba2e4443Sseb 		*val = bgep->param_lp_1000fdx;
10867c478bd9Sstevel@tonic-gate 		break;
10877c478bd9Sstevel@tonic-gate 
1088ba2e4443Sseb 	case ETHER_STAT_LP_CAP_1000HDX:
1089ba2e4443Sseb 		*val = bgep->param_lp_1000hdx;
10907c478bd9Sstevel@tonic-gate 		break;
10917c478bd9Sstevel@tonic-gate 
1092ba2e4443Sseb 	case ETHER_STAT_LP_CAP_100FDX:
1093ba2e4443Sseb 		*val = bgep->param_lp_100fdx;
10947c478bd9Sstevel@tonic-gate 		break;
10957c478bd9Sstevel@tonic-gate 
1096ba2e4443Sseb 	case ETHER_STAT_LP_CAP_100HDX:
1097ba2e4443Sseb 		*val = bgep->param_lp_100hdx;
10987c478bd9Sstevel@tonic-gate 		break;
10997c478bd9Sstevel@tonic-gate 
1100ba2e4443Sseb 	case ETHER_STAT_LP_CAP_10FDX:
1101ba2e4443Sseb 		*val = bgep->param_lp_10fdx;
11027c478bd9Sstevel@tonic-gate 		break;
11037c478bd9Sstevel@tonic-gate 
1104ba2e4443Sseb 	case ETHER_STAT_LP_CAP_10HDX:
1105ba2e4443Sseb 		*val = bgep->param_lp_10hdx;
11067c478bd9Sstevel@tonic-gate 		break;
11077c478bd9Sstevel@tonic-gate 
1108ba2e4443Sseb 	case ETHER_STAT_LP_CAP_ASMPAUSE:
1109ba2e4443Sseb 		*val = bgep->param_lp_asym_pause;
11107c478bd9Sstevel@tonic-gate 		break;
11117c478bd9Sstevel@tonic-gate 
1112ba2e4443Sseb 	case ETHER_STAT_LP_CAP_PAUSE:
1113ba2e4443Sseb 		*val = bgep->param_lp_pause;
11147c478bd9Sstevel@tonic-gate 		break;
11157c478bd9Sstevel@tonic-gate 
1116ba2e4443Sseb 	case ETHER_STAT_LP_CAP_AUTONEG:
1117ba2e4443Sseb 		*val = bgep->param_lp_autoneg;
11187c478bd9Sstevel@tonic-gate 		break;
11197c478bd9Sstevel@tonic-gate 
1120087a28d1SDavid Gwynne #if (MAC_VERSION > 1)
11219b14cf1dSgd 	case ETHER_STAT_LP_REMFAULT:
1122dca582a1Sgh 		if (bgep->chipid.flags & CHIP_FLAG_SERDES)
1123dca582a1Sgh 			*val = 0;
1124dca582a1Sgh 		else {
1125dca582a1Sgh 			mutex_enter(bgep->genlock);
1126dca582a1Sgh 			*val = bge_mii_get16(bgep, MII_AN_LPABLE) &
1127dca582a1Sgh 			    MII_AN_ADVERT_REMFAULT ? 1 : 0;
1128dca582a1Sgh 			if (bge_check_acc_handle(bgep, bgep->io_handle) !=
1129dca582a1Sgh 			    DDI_FM_OK) {
1130dca582a1Sgh 				ddi_fm_service_impact(bgep->devinfo,
1131dca582a1Sgh 				    DDI_SERVICE_UNAFFECTED);
1132dca582a1Sgh 			}
1133dca582a1Sgh 			mutex_exit(bgep->genlock);
11349b14cf1dSgd 		}
11359b14cf1dSgd 		break;
1136087a28d1SDavid Gwynne #endif
11379b14cf1dSgd 
1138ba2e4443Sseb 	case ETHER_STAT_LINK_ASMPAUSE:
1139ba2e4443Sseb 		*val = bgep->param_adv_asym_pause &&
11407c478bd9Sstevel@tonic-gate 		    bgep->param_lp_asym_pause &&
11417c478bd9Sstevel@tonic-gate 		    bgep->param_adv_pause != bgep->param_lp_pause;
1142f724721bSzh 		break;
11437c478bd9Sstevel@tonic-gate 
1144ba2e4443Sseb 	case ETHER_STAT_LINK_PAUSE:
1145ba2e4443Sseb 		*val = bgep->param_link_rx_pause;
11467c478bd9Sstevel@tonic-gate 		break;
11477c478bd9Sstevel@tonic-gate 
1148ba2e4443Sseb 	case ETHER_STAT_LINK_AUTONEG:
1149ba2e4443Sseb 		*val = bgep->param_link_autoneg;
11507c478bd9Sstevel@tonic-gate 		break;
11517c478bd9Sstevel@tonic-gate 
1152ba2e4443Sseb 	case ETHER_STAT_LINK_DUPLEX:
1153087a28d1SDavid Gwynne 		*val = (bgep->link_state != LINK_STATE_UNKNOWN) ?
1154087a28d1SDavid Gwynne 		           bgep->param_link_duplex : LINK_DUPLEX_UNKNOWN;
11557c478bd9Sstevel@tonic-gate 		break;
11567c478bd9Sstevel@tonic-gate 
11577c478bd9Sstevel@tonic-gate 	default:
1158ba2e4443Sseb 		return (ENOTSUP);
11597c478bd9Sstevel@tonic-gate 	}
11607c478bd9Sstevel@tonic-gate 
1161ba2e4443Sseb 	return (0);
11627c478bd9Sstevel@tonic-gate }
11630dc2366fSVenugopal Iyer 
11640dc2366fSVenugopal Iyer /*
11650dc2366fSVenugopal Iyer  * Retrieve a value for one of the statistics for a particular rx ring
11660dc2366fSVenugopal Iyer  */
11670dc2366fSVenugopal Iyer int
bge_rx_ring_stat(mac_ring_driver_t rh,uint_t stat,uint64_t * val)11680dc2366fSVenugopal Iyer bge_rx_ring_stat(mac_ring_driver_t rh, uint_t stat, uint64_t *val)
11690dc2366fSVenugopal Iyer {
11700dc2366fSVenugopal Iyer 	recv_ring_t *rx_ring = (recv_ring_t *)rh;
11710dc2366fSVenugopal Iyer 
11720dc2366fSVenugopal Iyer 	switch (stat) {
11730dc2366fSVenugopal Iyer 	case MAC_STAT_RBYTES:
11740dc2366fSVenugopal Iyer 		*val = rx_ring->rx_bytes;
11750dc2366fSVenugopal Iyer 		break;
11760dc2366fSVenugopal Iyer 
11770dc2366fSVenugopal Iyer 	case MAC_STAT_IPACKETS:
11780dc2366fSVenugopal Iyer 		*val = rx_ring->rx_pkts;
11790dc2366fSVenugopal Iyer 		break;
11800dc2366fSVenugopal Iyer 
11810dc2366fSVenugopal Iyer 	default:
11820dc2366fSVenugopal Iyer 		*val = 0;
11830dc2366fSVenugopal Iyer 		return (ENOTSUP);
11840dc2366fSVenugopal Iyer 	}
11850dc2366fSVenugopal Iyer 
11860dc2366fSVenugopal Iyer 	return (0);
11870dc2366fSVenugopal Iyer }
1188