xref: /illumos-gate/usr/src/uts/common/io/mac/mac_stat.c (revision 45948e49)
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
5ba2e4443Sseb  * Common Development and Distribution License (the "License").
6ba2e4443Sseb  * 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  */
217c478bd9Sstevel@tonic-gate /*
220dc2366fSVenugopal Iyer  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*45948e49SRyan Zezeski  * Copyright 2018 Joyent, Inc.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*
287c478bd9Sstevel@tonic-gate  * MAC Services Module
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
337c478bd9Sstevel@tonic-gate #include <sys/stream.h>
347c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
357c478bd9Sstevel@tonic-gate #include <sys/mac.h>
367c478bd9Sstevel@tonic-gate #include <sys/mac_impl.h>
370dc2366fSVenugopal Iyer #include <sys/mac_client_impl.h>
380dc2366fSVenugopal Iyer #include <sys/mac_stat.h>
390dc2366fSVenugopal Iyer #include <sys/mac_soft_ring.h>
400dc2366fSVenugopal Iyer #include <sys/vlan.h>
417c478bd9Sstevel@tonic-gate 
42ba2e4443Sseb #define	MAC_KSTAT_NAME	"mac"
43ba2e4443Sseb #define	MAC_KSTAT_CLASS	"net"
44ba2e4443Sseb 
450dc2366fSVenugopal Iyer enum mac_stat {
460dc2366fSVenugopal Iyer 	MAC_STAT_LCL,
470dc2366fSVenugopal Iyer 	MAC_STAT_LCLBYTES,
480dc2366fSVenugopal Iyer 	MAC_STAT_INTRS,
490dc2366fSVenugopal Iyer 	MAC_STAT_INTRBYTES,
500dc2366fSVenugopal Iyer 	MAC_STAT_POLLS,
510dc2366fSVenugopal Iyer 	MAC_STAT_POLLBYTES,
520dc2366fSVenugopal Iyer 	MAC_STAT_RXSDROPS,
530dc2366fSVenugopal Iyer 	MAC_STAT_CHU10,
540dc2366fSVenugopal Iyer 	MAC_STAT_CH10T50,
550dc2366fSVenugopal Iyer 	MAC_STAT_CHO50,
560dc2366fSVenugopal Iyer 	MAC_STAT_BLOCK,
570dc2366fSVenugopal Iyer 	MAC_STAT_UNBLOCK,
580dc2366fSVenugopal Iyer 	MAC_STAT_TXSDROPS,
590dc2366fSVenugopal Iyer 	MAC_STAT_TX_ERRORS,
600dc2366fSVenugopal Iyer 	MAC_STAT_MACSPOOFED,
610dc2366fSVenugopal Iyer 	MAC_STAT_IPSPOOFED,
620dc2366fSVenugopal Iyer 	MAC_STAT_DHCPSPOOFED,
630dc2366fSVenugopal Iyer 	MAC_STAT_RESTRICTED,
640dc2366fSVenugopal Iyer 	MAC_STAT_DHCPDROPPED,
650dc2366fSVenugopal Iyer 	MAC_STAT_MULTIRCVBYTES,
660dc2366fSVenugopal Iyer 	MAC_STAT_BRDCSTRCVBYTES,
670dc2366fSVenugopal Iyer 	MAC_STAT_MULTIXMTBYTES,
680dc2366fSVenugopal Iyer 	MAC_STAT_BRDCSTXMTBYTES
690dc2366fSVenugopal Iyer };
700dc2366fSVenugopal Iyer 
71ba2e4443Sseb static mac_stat_info_t	i_mac_si[] = {
72ba2e4443Sseb 	{ MAC_STAT_IFSPEED,	"ifspeed",	KSTAT_DATA_UINT64,	0 },
73ba2e4443Sseb 	{ MAC_STAT_MULTIRCV,	"multircv",	KSTAT_DATA_UINT32,	0 },
74ba2e4443Sseb 	{ MAC_STAT_BRDCSTRCV,	"brdcstrcv",	KSTAT_DATA_UINT32,	0 },
75ba2e4443Sseb 	{ MAC_STAT_MULTIXMT,	"multixmt",	KSTAT_DATA_UINT32,	0 },
76ba2e4443Sseb 	{ MAC_STAT_BRDCSTXMT,	"brdcstxmt",	KSTAT_DATA_UINT32,	0 },
77ba2e4443Sseb 	{ MAC_STAT_NORCVBUF,	"norcvbuf",	KSTAT_DATA_UINT32,	0 },
78ba2e4443Sseb 	{ MAC_STAT_IERRORS,	"ierrors",	KSTAT_DATA_UINT32,	0 },
79ba2e4443Sseb 	{ MAC_STAT_UNKNOWNS,	"unknowns",	KSTAT_DATA_UINT32,	0 },
80ba2e4443Sseb 	{ MAC_STAT_NOXMTBUF,	"noxmtbuf",	KSTAT_DATA_UINT32,	0 },
81ba2e4443Sseb 	{ MAC_STAT_OERRORS,	"oerrors",	KSTAT_DATA_UINT32,	0 },
82ba2e4443Sseb 	{ MAC_STAT_COLLISIONS,	"collisions",	KSTAT_DATA_UINT32,	0 },
839b14cf1dSgd 	{ MAC_STAT_UNDERFLOWS,	"uflo",		KSTAT_DATA_UINT32,	0 },
849b14cf1dSgd 	{ MAC_STAT_OVERFLOWS,	"oflo",		KSTAT_DATA_UINT32,	0 },
85ba2e4443Sseb 	{ MAC_STAT_RBYTES,	"rbytes",	KSTAT_DATA_UINT32,	0 },
86ba2e4443Sseb 	{ MAC_STAT_IPACKETS,	"ipackets",	KSTAT_DATA_UINT32,	0 },
87ba2e4443Sseb 	{ MAC_STAT_OBYTES,	"obytes",	KSTAT_DATA_UINT32,	0 },
88ba2e4443Sseb 	{ MAC_STAT_OPACKETS,	"opackets",	KSTAT_DATA_UINT32,	0 },
89ba2e4443Sseb 	{ MAC_STAT_RBYTES,	"rbytes64",	KSTAT_DATA_UINT64,	0 },
90ba2e4443Sseb 	{ MAC_STAT_IPACKETS,	"ipackets64",	KSTAT_DATA_UINT64,	0 },
91ba2e4443Sseb 	{ MAC_STAT_OBYTES,	"obytes64",	KSTAT_DATA_UINT64,	0 },
92ba2e4443Sseb 	{ MAC_STAT_OPACKETS,	"opackets64",	KSTAT_DATA_UINT64,	0 }
937c478bd9Sstevel@tonic-gate };
94ba2e4443Sseb #define	MAC_NKSTAT \
95ba2e4443Sseb 	(sizeof (i_mac_si) / sizeof (mac_stat_info_t))
96ba2e4443Sseb 
97ba2e4443Sseb static mac_stat_info_t	i_mac_mod_si[] = {
98ba2e4443Sseb 	{ MAC_STAT_LINK_STATE,	"link_state",	KSTAT_DATA_UINT32,
99ba2e4443Sseb 	    (uint64_t)LINK_STATE_UNKNOWN },
100ba2e4443Sseb 	{ MAC_STAT_LINK_UP,	"link_up",	KSTAT_DATA_UINT32,	0 },
101ba2e4443Sseb 	{ MAC_STAT_PROMISC,	"promisc",	KSTAT_DATA_UINT32,	0 }
102ba2e4443Sseb };
103ba2e4443Sseb #define	MAC_MOD_NKSTAT \
104ba2e4443Sseb 	(sizeof (i_mac_mod_si) / sizeof (mac_stat_info_t))
105ba2e4443Sseb 
106ba2e4443Sseb #define	MAC_MOD_KSTAT_OFFSET	0
107ba2e4443Sseb #define	MAC_KSTAT_OFFSET	MAC_MOD_KSTAT_OFFSET + MAC_MOD_NKSTAT
108ba2e4443Sseb #define	MAC_TYPE_KSTAT_OFFSET	MAC_KSTAT_OFFSET + MAC_NKSTAT
1097c478bd9Sstevel@tonic-gate 
1100dc2366fSVenugopal Iyer /*
1110dc2366fSVenugopal Iyer  * Definitions for per rx ring statistics
1120dc2366fSVenugopal Iyer  */
1130dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_rx_ring_si[] = {
1140dc2366fSVenugopal Iyer 	{ MAC_STAT_RBYTES,	"rbytes",	KSTAT_DATA_UINT64,	0},
1150dc2366fSVenugopal Iyer 	{ MAC_STAT_IPACKETS,	"ipackets",	KSTAT_DATA_UINT64,	0},
1160dc2366fSVenugopal Iyer 	{ MAC_STAT_HDROPS,	"hdrops",	KSTAT_DATA_UINT64,	0}
1170dc2366fSVenugopal Iyer };
1180dc2366fSVenugopal Iyer #define	MAC_RX_RING_NKSTAT \
1190dc2366fSVenugopal Iyer 	(sizeof (i_mac_rx_ring_si) / sizeof (mac_stat_info_t))
1200dc2366fSVenugopal Iyer 
1210dc2366fSVenugopal Iyer /*
1220dc2366fSVenugopal Iyer  * Definitions for per tx ring statistics
1230dc2366fSVenugopal Iyer  */
1240dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_tx_ring_si[] = {
1250dc2366fSVenugopal Iyer 	{ MAC_STAT_OBYTES,	"obytes",	KSTAT_DATA_UINT64,	0},
1260dc2366fSVenugopal Iyer 	{ MAC_STAT_OPACKETS,	"opackets",	KSTAT_DATA_UINT64,	0}
1270dc2366fSVenugopal Iyer };
1280dc2366fSVenugopal Iyer #define	MAC_TX_RING_NKSTAT \
1290dc2366fSVenugopal Iyer 	(sizeof (i_mac_tx_ring_si) / sizeof (mac_stat_info_t))
1300dc2366fSVenugopal Iyer 
1310dc2366fSVenugopal Iyer 
1320dc2366fSVenugopal Iyer /*
1330dc2366fSVenugopal Iyer  * Definitions for per software lane tx statistics
1340dc2366fSVenugopal Iyer  */
1350dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_tx_swlane_si[] = {
1360dc2366fSVenugopal Iyer 	{ MAC_STAT_OBYTES,	"obytes",	KSTAT_DATA_UINT64,	0},
1370dc2366fSVenugopal Iyer 	{ MAC_STAT_OPACKETS,	"opackets",	KSTAT_DATA_UINT64,	0},
1380dc2366fSVenugopal Iyer 	{ MAC_STAT_OERRORS,	"oerrors",	KSTAT_DATA_UINT64,	0},
1390dc2366fSVenugopal Iyer 	{ MAC_STAT_BLOCK,	"blockcnt",	KSTAT_DATA_UINT64,	0},
1400dc2366fSVenugopal Iyer 	{ MAC_STAT_UNBLOCK,	"unblockcnt",	KSTAT_DATA_UINT64,	0},
1410dc2366fSVenugopal Iyer 	{ MAC_STAT_TXSDROPS,	"txsdrops",	KSTAT_DATA_UINT64,	0}
1420dc2366fSVenugopal Iyer };
1430dc2366fSVenugopal Iyer #define	MAC_TX_SWLANE_NKSTAT \
1440dc2366fSVenugopal Iyer 	(sizeof (i_mac_tx_swlane_si) / sizeof (mac_stat_info_t))
1450dc2366fSVenugopal Iyer 
1460dc2366fSVenugopal Iyer /*
1470dc2366fSVenugopal Iyer  * Definitions for per software lane rx statistics
1480dc2366fSVenugopal Iyer  */
1490dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_rx_swlane_si[] = {
1500dc2366fSVenugopal Iyer 	{ MAC_STAT_IPACKETS,	"ipackets",	KSTAT_DATA_UINT64,	0},
1510dc2366fSVenugopal Iyer 	{ MAC_STAT_RBYTES,	"rbytes",	KSTAT_DATA_UINT64,	0},
1520dc2366fSVenugopal Iyer 	{ MAC_STAT_LCL,		"local",	KSTAT_DATA_UINT64,	0},
1530dc2366fSVenugopal Iyer 	{ MAC_STAT_LCLBYTES,	"localbytes",	KSTAT_DATA_UINT64,	0},
1540dc2366fSVenugopal Iyer 	{ MAC_STAT_INTRS,	"intrs",	KSTAT_DATA_UINT64,	0},
1550dc2366fSVenugopal Iyer 	{ MAC_STAT_INTRBYTES,	"intrbytes",	KSTAT_DATA_UINT64,	0},
1560dc2366fSVenugopal Iyer 	{ MAC_STAT_RXSDROPS,	"rxsdrops",	KSTAT_DATA_UINT64,	0}
1570dc2366fSVenugopal Iyer };
1580dc2366fSVenugopal Iyer #define	MAC_RX_SWLANE_NKSTAT \
1590dc2366fSVenugopal Iyer 	(sizeof (i_mac_rx_swlane_si) / sizeof (mac_stat_info_t))
1600dc2366fSVenugopal Iyer 
1610dc2366fSVenugopal Iyer /*
1620dc2366fSVenugopal Iyer  * Definitions for per hardware lane rx statistics
1630dc2366fSVenugopal Iyer  */
1640dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_rx_hwlane_si[] = {
1650dc2366fSVenugopal Iyer 	{ MAC_STAT_IPACKETS,	"ipackets",	KSTAT_DATA_UINT64,	0},
1660dc2366fSVenugopal Iyer 	{ MAC_STAT_RBYTES,	"rbytes",	KSTAT_DATA_UINT64,	0},
1670dc2366fSVenugopal Iyer 	{ MAC_STAT_INTRS,	"intrs",	KSTAT_DATA_UINT64,	0},
1680dc2366fSVenugopal Iyer 	{ MAC_STAT_INTRBYTES,	"intrbytes",	KSTAT_DATA_UINT64,	0},
1690dc2366fSVenugopal Iyer 	{ MAC_STAT_POLLS,	"polls",	KSTAT_DATA_UINT64,	0},
1700dc2366fSVenugopal Iyer 	{ MAC_STAT_POLLBYTES,	"pollbytes",	KSTAT_DATA_UINT64,	0},
1710dc2366fSVenugopal Iyer 	{ MAC_STAT_RXSDROPS,	"rxsdrops",	KSTAT_DATA_UINT64,	0},
1720dc2366fSVenugopal Iyer 	{ MAC_STAT_CHU10,	"chainunder10",	KSTAT_DATA_UINT64,	0},
1730dc2366fSVenugopal Iyer 	{ MAC_STAT_CH10T50,	"chain10to50",	KSTAT_DATA_UINT64,	0},
1740dc2366fSVenugopal Iyer 	{ MAC_STAT_CHO50,	"chainover50",	KSTAT_DATA_UINT64,	0}
1750dc2366fSVenugopal Iyer };
1760dc2366fSVenugopal Iyer #define	MAC_RX_HWLANE_NKSTAT \
1770dc2366fSVenugopal Iyer 	(sizeof (i_mac_rx_hwlane_si) / sizeof (mac_stat_info_t))
1780dc2366fSVenugopal Iyer 
1790dc2366fSVenugopal Iyer /*
1800dc2366fSVenugopal Iyer  * Definitions for misc statistics
1810dc2366fSVenugopal Iyer  */
1820dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_misc_si[] = {
1830dc2366fSVenugopal Iyer 	{ MAC_STAT_MULTIRCV,	"multircv",	KSTAT_DATA_UINT64,	0},
1840dc2366fSVenugopal Iyer 	{ MAC_STAT_BRDCSTRCV,	"brdcstrcv",	KSTAT_DATA_UINT64,	0},
1850dc2366fSVenugopal Iyer 	{ MAC_STAT_MULTIXMT,	"multixmt",	KSTAT_DATA_UINT64,	0},
1860dc2366fSVenugopal Iyer 	{ MAC_STAT_BRDCSTXMT,	"brdcstxmt",	KSTAT_DATA_UINT64,	0},
1870dc2366fSVenugopal Iyer 	{ MAC_STAT_MULTIRCVBYTES, "multircvbytes",   KSTAT_DATA_UINT64,	0},
1880dc2366fSVenugopal Iyer 	{ MAC_STAT_BRDCSTRCVBYTES, "brdcstrcvbytes", KSTAT_DATA_UINT64,	0},
1890dc2366fSVenugopal Iyer 	{ MAC_STAT_MULTIXMTBYTES,  "multixmtbytes",  KSTAT_DATA_UINT64,	0},
1900dc2366fSVenugopal Iyer 	{ MAC_STAT_BRDCSTXMTBYTES, "brdcstxmtbytes", KSTAT_DATA_UINT64,	0},
1910dc2366fSVenugopal Iyer 	{ MAC_STAT_TX_ERRORS,	"txerrors",	KSTAT_DATA_UINT64,	0},
1920dc2366fSVenugopal Iyer 	{ MAC_STAT_MACSPOOFED,	"macspoofed",	KSTAT_DATA_UINT64,	0},
1930dc2366fSVenugopal Iyer 	{ MAC_STAT_IPSPOOFED,	"ipspoofed",	KSTAT_DATA_UINT64,	0},
1940dc2366fSVenugopal Iyer 	{ MAC_STAT_DHCPSPOOFED,	"dhcpspoofed",	KSTAT_DATA_UINT64,	0},
1950dc2366fSVenugopal Iyer 	{ MAC_STAT_RESTRICTED,	"restricted",	KSTAT_DATA_UINT64,	0},
1960dc2366fSVenugopal Iyer 	{ MAC_STAT_DHCPDROPPED,	"dhcpdropped",	KSTAT_DATA_UINT64,	0},
1970dc2366fSVenugopal Iyer 	{ MAC_STAT_IPACKETS,	"ipackets",	KSTAT_DATA_UINT64,	0},
1980dc2366fSVenugopal Iyer 	{ MAC_STAT_RBYTES,	"rbytes",	KSTAT_DATA_UINT64,	0},
1990dc2366fSVenugopal Iyer 	{ MAC_STAT_LCL,		"local",	KSTAT_DATA_UINT64,	0},
2000dc2366fSVenugopal Iyer 	{ MAC_STAT_LCLBYTES,	"localbytes",	KSTAT_DATA_UINT64,	0},
2010dc2366fSVenugopal Iyer 	{ MAC_STAT_INTRS,	"intrs",	KSTAT_DATA_UINT64,	0},
2020dc2366fSVenugopal Iyer 	{ MAC_STAT_INTRBYTES,	"intrbytes",	KSTAT_DATA_UINT64,	0},
2030dc2366fSVenugopal Iyer 	{ MAC_STAT_POLLS,	"polls",	KSTAT_DATA_UINT64,	0},
2040dc2366fSVenugopal Iyer 	{ MAC_STAT_POLLBYTES,	"pollbytes",	KSTAT_DATA_UINT64,	0},
2050dc2366fSVenugopal Iyer 	{ MAC_STAT_RXSDROPS,	"rxsdrops",	KSTAT_DATA_UINT64,	0},
2060dc2366fSVenugopal Iyer 	{ MAC_STAT_CHU10,	"chainunder10",	KSTAT_DATA_UINT64,	0},
2070dc2366fSVenugopal Iyer 	{ MAC_STAT_CH10T50,	"chain10to50",	KSTAT_DATA_UINT64,	0},
2080dc2366fSVenugopal Iyer 	{ MAC_STAT_CHO50,	"chainover50",	KSTAT_DATA_UINT64,	0},
2090dc2366fSVenugopal Iyer 	{ MAC_STAT_OBYTES,	"obytes",	KSTAT_DATA_UINT64,	0},
2100dc2366fSVenugopal Iyer 	{ MAC_STAT_OPACKETS,	"opackets",	KSTAT_DATA_UINT64,	0},
2110dc2366fSVenugopal Iyer 	{ MAC_STAT_OERRORS,	"oerrors",	KSTAT_DATA_UINT64,	0},
2120dc2366fSVenugopal Iyer 	{ MAC_STAT_BLOCK,	"blockcnt",	KSTAT_DATA_UINT64,	0},
2130dc2366fSVenugopal Iyer 	{ MAC_STAT_UNBLOCK,	"unblockcnt",	KSTAT_DATA_UINT64,	0},
2140dc2366fSVenugopal Iyer 	{ MAC_STAT_TXSDROPS,	"txsdrops",	KSTAT_DATA_UINT64,	0}
2150dc2366fSVenugopal Iyer };
2160dc2366fSVenugopal Iyer #define	MAC_SUMMARY_NKSTAT \
2170dc2366fSVenugopal Iyer 	(sizeof (i_mac_misc_si) / sizeof (mac_stat_info_t))
2180dc2366fSVenugopal Iyer 
2190dc2366fSVenugopal Iyer /*
2200dc2366fSVenugopal Iyer  * Definitions for per hardware lane tx statistics
2210dc2366fSVenugopal Iyer  */
2220dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_tx_hwlane_si[] = {
2230dc2366fSVenugopal Iyer 	{ MAC_STAT_OBYTES,	"obytes",	KSTAT_DATA_UINT64,	0},
2240dc2366fSVenugopal Iyer 	{ MAC_STAT_OPACKETS,	"opackets",	KSTAT_DATA_UINT64,	0},
2250dc2366fSVenugopal Iyer 	{ MAC_STAT_OERRORS,	"oerrors",	KSTAT_DATA_UINT64,	0},
2260dc2366fSVenugopal Iyer 	{ MAC_STAT_BLOCK,	"blockcnt",	KSTAT_DATA_UINT64,	0},
2270dc2366fSVenugopal Iyer 	{ MAC_STAT_UNBLOCK,	"unblockcnt",	KSTAT_DATA_UINT64,	0},
2280dc2366fSVenugopal Iyer 	{ MAC_STAT_TXSDROPS,	"txsdrops",	KSTAT_DATA_UINT64,	0}
2290dc2366fSVenugopal Iyer };
2300dc2366fSVenugopal Iyer #define	MAC_TX_HWLANE_NKSTAT \
2310dc2366fSVenugopal Iyer 	(sizeof (i_mac_tx_hwlane_si) / sizeof (mac_stat_info_t))
2320dc2366fSVenugopal Iyer 
2330dc2366fSVenugopal Iyer /*
2340dc2366fSVenugopal Iyer  * Definitions for per fanout rx statistics
2350dc2366fSVenugopal Iyer  */
2360dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_rx_fanout_si[] = {
2370dc2366fSVenugopal Iyer 	{ MAC_STAT_RBYTES,	"rbytes",	KSTAT_DATA_UINT64,	0},
2380dc2366fSVenugopal Iyer 	{ MAC_STAT_IPACKETS,	"ipackets",	KSTAT_DATA_UINT64,	0},
2390dc2366fSVenugopal Iyer };
2400dc2366fSVenugopal Iyer #define	MAC_RX_FANOUT_NKSTAT \
2410dc2366fSVenugopal Iyer 	(sizeof (i_mac_rx_fanout_si) / sizeof (mac_stat_info_t))
2420dc2366fSVenugopal Iyer 
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate  * Private functions.
2457c478bd9Sstevel@tonic-gate  */
2467c478bd9Sstevel@tonic-gate 
2470dc2366fSVenugopal Iyer typedef struct {
2480dc2366fSVenugopal Iyer 	uint_t	si_offset;
2490dc2366fSVenugopal Iyer } stat_info_t;
2500dc2366fSVenugopal Iyer 
2510dc2366fSVenugopal Iyer #define	RX_SRS_STAT_OFF(f)	(offsetof(mac_rx_stats_t, f))
2520dc2366fSVenugopal Iyer static stat_info_t rx_srs_stats_list[] = {
2530dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_lclbytes)},
2540dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_lclcnt)},
2550dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_pollcnt)},
2560dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_pollbytes)},
2570dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_intrcnt)},
2580dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_intrbytes)},
2590dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_sdrops)},
2600dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_chaincntundr10)},
2610dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_chaincnt10to50)},
2620dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_chaincntover50)},
2630dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_ierrors)}
2640dc2366fSVenugopal Iyer };
265*45948e49SRyan Zezeski #define	RX_SRS_STAT_SIZE		\
2660dc2366fSVenugopal Iyer 	(sizeof (rx_srs_stats_list) / sizeof (stat_info_t))
2670dc2366fSVenugopal Iyer 
2680dc2366fSVenugopal Iyer #define	TX_SOFTRING_STAT_OFF(f)	(offsetof(mac_tx_stats_t, f))
2690dc2366fSVenugopal Iyer static stat_info_t tx_softring_stats_list[] = {
2700dc2366fSVenugopal Iyer 	{TX_SOFTRING_STAT_OFF(mts_obytes)},
2710dc2366fSVenugopal Iyer 	{TX_SOFTRING_STAT_OFF(mts_opackets)},
2720dc2366fSVenugopal Iyer 	{TX_SOFTRING_STAT_OFF(mts_oerrors)},
2730dc2366fSVenugopal Iyer 	{TX_SOFTRING_STAT_OFF(mts_blockcnt)},
2740dc2366fSVenugopal Iyer 	{TX_SOFTRING_STAT_OFF(mts_unblockcnt)},
2750dc2366fSVenugopal Iyer 	{TX_SOFTRING_STAT_OFF(mts_sdrops)},
2760dc2366fSVenugopal Iyer };
277*45948e49SRyan Zezeski #define	TX_SOFTRING_STAT_SIZE		\
2780dc2366fSVenugopal Iyer 	(sizeof (tx_softring_stats_list) / sizeof (stat_info_t))
2790dc2366fSVenugopal Iyer 
2800dc2366fSVenugopal Iyer static void
i_mac_add_stats(void * sum,void * op1,void * op2,stat_info_t stats_list[],uint_t size)2810dc2366fSVenugopal Iyer i_mac_add_stats(void *sum, void *op1, void *op2,
2820dc2366fSVenugopal Iyer     stat_info_t stats_list[], uint_t size)
2830dc2366fSVenugopal Iyer {
284*45948e49SRyan Zezeski 	int	i;
2850dc2366fSVenugopal Iyer 
2860dc2366fSVenugopal Iyer 	for (i = 0; i < size; i++) {
2870dc2366fSVenugopal Iyer 		uint64_t *op1_val = (uint64_t *)
2880dc2366fSVenugopal Iyer 		    ((uchar_t *)op1 + stats_list[i].si_offset);
2890dc2366fSVenugopal Iyer 		uint64_t *op2_val = (uint64_t *)
2900dc2366fSVenugopal Iyer 		    ((uchar_t *)op2 + stats_list[i].si_offset);
2910dc2366fSVenugopal Iyer 		uint64_t *sum_val = (uint64_t *)
2920dc2366fSVenugopal Iyer 		    ((uchar_t *)sum + stats_list[i].si_offset);
2930dc2366fSVenugopal Iyer 
2940dc2366fSVenugopal Iyer 		*sum_val =  *op1_val + *op2_val;
2950dc2366fSVenugopal Iyer 	}
2960dc2366fSVenugopal Iyer }
2970dc2366fSVenugopal Iyer 
2987c478bd9Sstevel@tonic-gate static int
i_mac_driver_stat_update(kstat_t * ksp,int rw)2990dc2366fSVenugopal Iyer i_mac_driver_stat_update(kstat_t *ksp, int rw)
3007c478bd9Sstevel@tonic-gate {
3017c478bd9