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 {
3017c478bd9Sstevel@tonic-gate 	mac_impl_t	*mip = ksp->ks_private;
302ba2e4443Sseb 	kstat_named_t	*knp = ksp->ks_data;
3037c478bd9Sstevel@tonic-gate 	uint_t		i;
3047c478bd9Sstevel@tonic-gate 	uint64_t	val;
305ba2e4443Sseb 	mac_stat_info_t	*msi;
306ba2e4443Sseb 	uint_t		msi_index;
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate 	if (rw != KSTAT_READ)
3097c478bd9Sstevel@tonic-gate 		return (EACCES);
3107c478bd9Sstevel@tonic-gate 
311ba2e4443Sseb 	for (i = 0; i < mip->mi_kstat_count; i++, msi_index++) {
312ba2e4443Sseb 		if (i == MAC_MOD_KSTAT_OFFSET) {
313ba2e4443Sseb 			msi_index = 0;
314ba2e4443Sseb 			msi = i_mac_mod_si;
315ba2e4443Sseb 		} else if (i == MAC_KSTAT_OFFSET) {
316ba2e4443Sseb 			msi_index = 0;
317ba2e4443Sseb 			msi = i_mac_si;
318ba2e4443Sseb 		} else if (i == MAC_TYPE_KSTAT_OFFSET) {
319ba2e4443Sseb 			msi_index = 0;
320ba2e4443Sseb 			msi = mip->mi_type->mt_stats;
321ba2e4443Sseb 		}
3227c478bd9Sstevel@tonic-gate 
323ba2e4443Sseb 		val = mac_stat_get((mac_handle_t)mip, msi[msi_index].msi_stat);
324ba2e4443Sseb 		switch (msi[msi_index].msi_type) {
3257c478bd9Sstevel@tonic-gate 		case KSTAT_DATA_UINT64:
3267c478bd9Sstevel@tonic-gate 			knp->value.ui64 = val;
3277c478bd9Sstevel@tonic-gate 			break;
3287c478bd9Sstevel@tonic-gate 		case KSTAT_DATA_UINT32:
3297c478bd9Sstevel@tonic-gate 			knp->value.ui32 = (uint32_t)val;
3307c478bd9Sstevel@tonic-gate 			break;
3317c478bd9Sstevel@tonic-gate 		default:
3327c478bd9Sstevel@tonic-gate 			ASSERT(B_FALSE);
3337c478bd9Sstevel@tonic-gate 			break;
3347c478bd9Sstevel@tonic-gate 		}
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 		knp++;
3377c478bd9Sstevel@tonic-gate 	}
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate 	return (0);
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate 
342ba2e4443Sseb static void
i_mac_kstat_init(kstat_named_t * knp,mac_stat_info_t * si,uint_t count)343ba2e4443Sseb i_mac_kstat_init(kstat_named_t *knp, mac_stat_info_t *si, uint_t count)
344ba2e4443Sseb {
345ba2e4443Sseb 	int i;
346ba2e4443Sseb 	for (i = 0; i < count; i++) {
347ba2e4443Sseb 		kstat_named_init(knp, si[i].msi_name, si[i].msi_type);
348ba2e4443Sseb 		knp++;
349ba2e4443Sseb 	}
350ba2e4443Sseb }
351ba2e4443Sseb 
3520dc2366fSVenugopal Iyer static int
i_mac_stat_update(kstat_t * ksp,int rw,uint64_t (* fn)(void *,uint_t),mac_stat_info_t * msi,uint_t count)3530dc2366fSVenugopal Iyer i_mac_stat_update(kstat_t *ksp, int rw, uint64_t (*fn)(void *, uint_t),
3540dc2366fSVenugopal Iyer     mac_stat_info_t *msi, uint_t count)
3550dc2366fSVenugopal Iyer {
3560dc2366fSVenugopal Iyer 	kstat_named_t	*knp = ksp->ks_data;
3570dc2366fSVenugopal Iyer 	uint_t		i;
3580dc2366fSVenugopal Iyer 	uint64_t	val;
3590dc2366fSVenugopal Iyer 
3600dc2366fSVenugopal Iyer 	if (rw != KSTAT_READ)
3610dc2366fSVenugopal Iyer 		return (EACCES);
3620dc2366fSVenugopal Iyer 
3630dc2366fSVenugopal Iyer 	for (i = 0; i < count; i++) {
3640dc2366fSVenugopal Iyer 		val = fn(ksp->ks_private, msi[i].msi_stat);
3650dc2366fSVenugopal Iyer 
3660dc2366fSVenugopal Iyer 		switch (msi[i].msi_type) {
3670dc2366fSVenugopal Iyer 		case KSTAT_DATA_UINT64:
3680dc2366fSVenugopal Iyer 			knp->value.ui64 = val;
3690dc2366fSVenugopal Iyer 			break;
3700dc2366fSVenugopal Iyer 		case KSTAT_DATA_UINT32:
3710dc2366fSVenugopal Iyer 			knp->value.ui32 = (uint32_t)val;
3720dc2366fSVenugopal Iyer 			break;
3730dc2366fSVenugopal Iyer 		default:
3740dc2366fSVenugopal Iyer 			ASSERT(B_FALSE);
3750dc2366fSVenugopal Iyer 			break;
3760dc2366fSVenugopal Iyer 		}
3770dc2366fSVenugopal Iyer 		knp++;
3780dc2366fSVenugopal Iyer 	}
3790dc2366fSVenugopal Iyer 	return (0);
3800dc2366fSVenugopal Iyer }
3810dc2366fSVenugopal Iyer 
3820dc2366fSVenugopal Iyer /*
3830dc2366fSVenugopal Iyer  * Create kstat with given name - statname, update function - fn
3840dc2366fSVenugopal Iyer  * and initialize it with given names - init_stat_info
3850dc2366fSVenugopal Iyer  */
3860dc2366fSVenugopal Iyer static kstat_t *
i_mac_stat_create(void * handle,const char * modname,const char * statname,int (* fn)(kstat_t *,int),mac_stat_info_t * init_stat_info,uint_t count)3870dc2366fSVenugopal Iyer i_mac_stat_create(void *handle, const char *modname, const char *statname,
3880dc2366fSVenugopal Iyer     int (*fn) (kstat_t *, int),
3890dc2366fSVenugopal Iyer     mac_stat_info_t *init_stat_info, uint_t count)
3900dc2366fSVenugopal Iyer {
3910dc2366fSVenugopal Iyer 	kstat_t		*ksp;
3920dc2366fSVenugopal Iyer 	kstat_named_t	*knp;
3930dc2366fSVenugopal Iyer 
3940dc2366fSVenugopal Iyer 	ksp = kstat_create(modname, 0, statname, "net",
3950dc2366fSVenugopal Iyer 	    KSTAT_TYPE_NAMED, count, 0);
3960dc2366fSVenugopal Iyer 
3970dc2366fSVenugopal Iyer 	if (ksp == NULL)
3980dc2366fSVenugopal Iyer 		return (NULL);
3990dc2366fSVenugopal Iyer 
4000dc2366fSVenugopal Iyer 	ksp->ks_update = fn;
4010dc2366fSVenugopal Iyer 	ksp->ks_private = handle;
4020dc2366fSVenugopal Iyer 
4030dc2366fSVenugopal Iyer 	knp = (kstat_named_t *)ksp->ks_data;
4040dc2366fSVenugopal Iyer 	i_mac_kstat_init(knp, init_stat_info, count);
4050dc2366fSVenugopal Iyer 	kstat_install(ksp);
4060dc2366fSVenugopal Iyer 
4070dc2366fSVenugopal Iyer 	return (ksp);
4080dc2366fSVenugopal Iyer }
4090dc2366fSVenugopal Iyer 
4100dc2366fSVenugopal Iyer /*
4110dc2366fSVenugopal Iyer  * Per rx ring statistics
4120dc2366fSVenugopal Iyer  */
4130dc2366fSVenugopal Iyer uint64_t
mac_rx_ring_stat_get(void * handle,uint_t stat)4140dc2366fSVenugopal Iyer mac_rx_ring_stat_get(void *handle, uint_t stat)
4150dc2366fSVenugopal Iyer {
4160dc2366fSVenugopal Iyer 	mac_ring_t		*ring = (mac_ring_t *)handle;
4170dc2366fSVenugopal Iyer 	uint64_t		val = 0;
4180dc2366fSVenugopal Iyer 
4190dc2366fSVenugopal Iyer 	/*
4200dc2366fSVenugopal Iyer 	 * XXX Every ring-capable driver must implement an entry point to
4210dc2366fSVenugopal Iyer 	 * query per ring statistics. CR 6893122 tracks this work item.
4220dc2366fSVenugopal Iyer 	 * Once this bug is fixed, the framework should fail registration
4230dc2366fSVenugopal Iyer 	 * for a driver that does not implement this entry point and
4240dc2366fSVenugopal Iyer 	 * assert ring->mr_stat != NULL here.
4250dc2366fSVenugopal Iyer 	 */
4260dc2366fSVenugopal Iyer 	if (ring->mr_stat != NULL)
4270dc2366fSVenugopal Iyer 		ring->mr_stat(ring->mr_driver, stat, &val);
4280dc2366fSVenugopal Iyer 
4290dc2366fSVenugopal Iyer 	return (val);
4300dc2366fSVenugopal Iyer }
4310dc2366fSVenugopal Iyer 
4320dc2366fSVenugopal Iyer static int
i_mac_rx_ring_stat_update(kstat_t * ksp,int rw)4330dc2366fSVenugopal Iyer i_mac_rx_ring_stat_update(kstat_t *ksp, int rw)
4340dc2366fSVenugopal Iyer {
4350dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, mac_rx_ring_stat_get,
4360dc2366fSVenugopal Iyer 	    i_mac_rx_ring_si, MAC_RX_RING_NKSTAT));
4370dc2366fSVenugopal Iyer }
4380dc2366fSVenugopal Iyer 
4390dc2366fSVenugopal Iyer static void
i_mac_rx_ring_stat_create(mac_ring_t * ring,const char * modname,const char * statname)4400dc2366fSVenugopal Iyer i_mac_rx_ring_stat_create(mac_ring_t *ring, const char *modname,
4410dc2366fSVenugopal Iyer     const char *statname)
4420dc2366fSVenugopal Iyer {
4430dc2366fSVenugopal Iyer 	kstat_t		*ksp;
4440dc2366fSVenugopal Iyer 
4450dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(ring, modname, statname,
4460dc2366fSVenugopal Iyer 	    i_mac_rx_ring_stat_update, i_mac_rx_ring_si, MAC_RX_RING_NKSTAT);
4470dc2366fSVenugopal Iyer 
4480dc2366fSVenugopal Iyer 	ring->mr_ksp = ksp;
4490dc2366fSVenugopal Iyer }
4500dc2366fSVenugopal Iyer 
4510dc2366fSVenugopal Iyer /*
4520dc2366fSVenugopal Iyer  * Per tx ring statistics
4530dc2366fSVenugopal Iyer  */
4540dc2366fSVenugopal Iyer uint64_t
mac_tx_ring_stat_get(void * handle,uint_t stat)4550dc2366fSVenugopal Iyer mac_tx_ring_stat_get(void *handle, uint_t stat)
4560dc2366fSVenugopal Iyer {
4570dc2366fSVenugopal Iyer 	mac_ring_t		*ring = (mac_ring_t *)handle;
4580dc2366fSVenugopal Iyer 	uint64_t		val = 0;
4590dc2366fSVenugopal Iyer 
4600dc2366fSVenugopal Iyer 	/*
4610dc2366fSVenugopal Iyer 	 * XXX Every ring-capable driver must implement an entry point to
4620dc2366fSVenugopal Iyer 	 * query per ring statistics. CR 6893122 tracks this work item.
4630dc2366fSVenugopal Iyer 	 * Once this bug is fixed, the framework should fail registration
4640dc2366fSVenugopal Iyer 	 * for a driver that does not implement this entry point and
4650dc2366fSVenugopal Iyer 	 * assert ring->mr_stat != NULL here.
4660dc2366fSVenugopal Iyer 	 */
4670dc2366fSVenugopal Iyer 	if (ring->mr_stat != NULL)
4680dc2366fSVenugopal Iyer 		ring->mr_stat(ring->mr_driver, stat, &val);
4690dc2366fSVenugopal Iyer 
4700dc2366fSVenugopal Iyer 	return (val);
4710dc2366fSVenugopal Iyer }
4720dc2366fSVenugopal Iyer 
4730dc2366fSVenugopal Iyer static int
i_mac_tx_ring_stat_update(kstat_t * ksp,int rw)4740dc2366fSVenugopal Iyer i_mac_tx_ring_stat_update(kstat_t *ksp, int rw)
4750dc2366fSVenugopal Iyer {
4760dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, mac_tx_ring_stat_get,
4770dc2366fSVenugopal Iyer 	    i_mac_tx_ring_si, MAC_TX_RING_NKSTAT));
4780dc2366fSVenugopal Iyer }
4790dc2366fSVenugopal Iyer 
4800dc2366fSVenugopal Iyer static void
i_mac_tx_ring_stat_create(mac_ring_t * ring,const char * modname,const char * statname)4810dc2366fSVenugopal Iyer i_mac_tx_ring_stat_create(mac_ring_t *ring, const char *modname,
4820dc2366fSVenugopal Iyer     const char *statname)
4830dc2366fSVenugopal Iyer {
4840dc2366fSVenugopal Iyer 	kstat_t		*ksp;
4850dc2366fSVenugopal Iyer 
4860dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(ring, modname, statname,
4870dc2366fSVenugopal Iyer 	    i_mac_tx_ring_stat_update, i_mac_tx_ring_si, MAC_TX_RING_NKSTAT);
4880dc2366fSVenugopal Iyer 
4890dc2366fSVenugopal Iyer 	ring->mr_ksp = ksp;
4900dc2366fSVenugopal Iyer }
4910dc2366fSVenugopal Iyer 
4920dc2366fSVenugopal Iyer /*
4930dc2366fSVenugopal Iyer  * Per software lane tx statistics
4940dc2366fSVenugopal Iyer  */
4950dc2366fSVenugopal Iyer static uint64_t
i_mac_tx_swlane_stat_get(void * handle,uint_t stat)4960dc2366fSVenugopal Iyer i_mac_tx_swlane_stat_get(void *handle, uint_t stat)
4970dc2366fSVenugopal Iyer {
4980dc2366fSVenugopal Iyer 	mac_soft_ring_set_t *mac_srs = (mac_soft_ring_set_t *)handle;
4990dc2366fSVenugopal Iyer 	mac_tx_stats_t *mac_tx_stat = &mac_srs->srs_tx.st_stat;
5000dc2366fSVenugopal Iyer 
5010dc2366fSVenugopal Iyer 	switch (stat) {
5020dc2366fSVenugopal Iyer 	case MAC_STAT_OBYTES:
5030dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_obytes);
5040dc2366fSVenugopal Iyer 
5050dc2366fSVenugopal Iyer 	case MAC_STAT_OPACKETS:
5060dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_opackets);
5070dc2366fSVenugopal Iyer 
5080dc2366fSVenugopal Iyer 	case MAC_STAT_OERRORS:
5090dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_oerrors);
5100dc2366fSVenugopal Iyer 
5110dc2366fSVenugopal Iyer 	case MAC_STAT_BLOCK:
5120dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_blockcnt);
5130dc2366fSVenugopal Iyer 
5140dc2366fSVenugopal Iyer 	case MAC_STAT_UNBLOCK:
5150dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_unblockcnt);
5160dc2366fSVenugopal Iyer 
5170dc2366fSVenugopal Iyer 	case MAC_STAT_TXSDROPS:
5180dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_sdrops);
5190dc2366fSVenugopal Iyer 
5200dc2366fSVenugopal Iyer 	default:
5210dc2366fSVenugopal Iyer 		return (0);
5220dc2366fSVenugopal Iyer 	}
5230dc2366fSVenugopal Iyer }
5240dc2366fSVenugopal Iyer 
5250dc2366fSVenugopal Iyer static int
i_mac_tx_swlane_stat_update(kstat_t * ksp,int rw)5260dc2366fSVenugopal Iyer i_mac_tx_swlane_stat_update(kstat_t *ksp, int rw)
5270dc2366fSVenugopal Iyer {
5280dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, i_mac_tx_swlane_stat_get,
5290dc2366fSVenugopal Iyer 	    i_mac_tx_swlane_si, MAC_TX_SWLANE_NKSTAT));
5300dc2366fSVenugopal Iyer }
5310dc2366fSVenugopal Iyer 
5320dc2366fSVenugopal Iyer static void
i_mac_tx_swlane_stat_create(mac_soft_ring_set_t * mac_srs,const char * modname,const char * statname)5330dc2366fSVenugopal Iyer i_mac_tx_swlane_stat_create(mac_soft_ring_set_t *mac_srs, const char *modname,
5340dc2366fSVenugopal Iyer     const char *statname)
5350dc2366fSVenugopal Iyer {
5360dc2366fSVenugopal Iyer 	kstat_t		*ksp;
5370dc2366fSVenugopal Iyer 
5380dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(mac_srs, modname, statname,
5390dc2366fSVenugopal Iyer 	    i_mac_tx_swlane_stat_update, i_mac_tx_swlane_si,
5400dc2366fSVenugopal Iyer 	    MAC_TX_SWLANE_NKSTAT);
5410dc2366fSVenugopal Iyer 
5420dc2366fSVenugopal Iyer 	mac_srs->srs_ksp = ksp;
5430dc2366fSVenugopal Iyer }
5440dc2366fSVenugopal Iyer 
5450dc2366fSVenugopal Iyer /*
5460dc2366fSVenugopal Iyer  * Per software lane rx statistics
5470dc2366fSVenugopal Iyer  */
5480dc2366fSVenugopal Iyer static uint64_t
i_mac_rx_swlane_stat_get(void * handle,uint_t stat)5490dc2366fSVenugopal Iyer i_mac_rx_swlane_stat_get(void *handle, uint_t stat)
5500dc2366fSVenugopal Iyer {
5510dc2366fSVenugopal Iyer 	mac_soft_ring_set_t	*mac_srs = (mac_soft_ring_set_t *)handle;
5520dc2366fSVenugopal Iyer 	mac_rx_stats_t		*mac_rx_stat = &mac_srs->srs_rx.sr_stat;
5530dc2366fSVenugopal Iyer 
5540dc2366fSVenugopal Iyer 	switch (stat) {
5550dc2366fSVenugopal Iyer 	case MAC_STAT_IPACKETS:
5560dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrcnt +
5570dc2366fSVenugopal Iyer 		    mac_rx_stat->mrs_lclcnt);
5580dc2366fSVenugopal Iyer 
5590dc2366fSVenugopal Iyer 	case MAC_STAT_RBYTES:
5600dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrbytes +
5610dc2366fSVenugopal Iyer 		    mac_rx_stat->mrs_lclbytes);
5620dc2366fSVenugopal Iyer 
5630dc2366fSVenugopal Iyer 	case MAC_STAT_LCL:
5640dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_lclcnt);
5650dc2366fSVenugopal Iyer 
5660dc2366fSVenugopal Iyer 	case MAC_STAT_LCLBYTES:
5670dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_lclbytes);
5680dc2366fSVenugopal Iyer 
5690dc2366fSVenugopal Iyer 	case MAC_STAT_INTRS:
5700dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrcnt);
5710dc2366fSVenugopal Iyer 
5720dc2366fSVenugopal Iyer 	case MAC_STAT_INTRBYTES:
5730dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrbytes);
5740dc2366fSVenugopal Iyer 
5750dc2366fSVenugopal Iyer 	case MAC_STAT_RXSDROPS:
5760dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_sdrops);
5770dc2366fSVenugopal Iyer 
5780dc2366fSVenugopal Iyer 	default:
5790dc2366fSVenugopal Iyer 		return (0);
5800dc2366fSVenugopal Iyer 	}
5810dc2366fSVenugopal Iyer }
5820dc2366fSVenugopal Iyer 
5830dc2366fSVenugopal Iyer static int
i_mac_rx_swlane_stat_update(kstat_t * ksp,int rw)5840dc2366fSVenugopal Iyer i_mac_rx_swlane_stat_update(kstat_t *ksp, int rw)
5850dc2366fSVenugopal Iyer {
5860dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, i_mac_rx_swlane_stat_get,
5870dc2366fSVenugopal Iyer 	    i_mac_rx_swlane_si, MAC_RX_SWLANE_NKSTAT));
5880dc2366fSVenugopal Iyer }
5890dc2366fSVenugopal Iyer 
5900dc2366fSVenugopal Iyer static void
i_mac_rx_swlane_stat_create(mac_soft_ring_set_t * mac_srs,const char * modname,const char * statname)5910dc2366fSVenugopal Iyer i_mac_rx_swlane_stat_create(mac_soft_ring_set_t *mac_srs, const char *modname,
5920dc2366fSVenugopal Iyer     const char *statname)
5930dc2366fSVenugopal Iyer {
5940dc2366fSVenugopal Iyer 	kstat_t		*ksp;
5950dc2366fSVenugopal Iyer 
5960dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(mac_srs, modname, statname,
5970dc2366fSVenugopal Iyer 	    i_mac_rx_swlane_stat_update, i_mac_rx_swlane_si,
5980dc2366fSVenugopal Iyer 	    MAC_RX_SWLANE_NKSTAT);
5990dc2366fSVenugopal Iyer 
6000dc2366fSVenugopal Iyer 	mac_srs->srs_ksp = ksp;
6010dc2366fSVenugopal Iyer }
6020dc2366fSVenugopal Iyer 
6030dc2366fSVenugopal Iyer 
6040dc2366fSVenugopal Iyer /*
6050dc2366fSVenugopal Iyer  * Per hardware lane rx statistics
6060dc2366fSVenugopal Iyer  */
6070dc2366fSVenugopal Iyer static uint64_t
i_mac_rx_hwlane_stat_get(void * handle,uint_t stat)6080dc2366fSVenugopal Iyer i_mac_rx_hwlane_stat_get(void *handle, uint_t stat)
6090dc2366fSVenugopal Iyer {
6100dc2366fSVenugopal Iyer 	mac_soft_ring_set_t	*mac_srs = (mac_soft_ring_set_t *)handle;
6110dc2366fSVenugopal Iyer 	mac_rx_stats_t		*mac_rx_stat = &mac_srs->srs_rx.sr_stat;
6120dc2366fSVenugopal Iyer 
6130dc2366fSVenugopal Iyer 	switch (stat) {
6140dc2366fSVenugopal Iyer 	case MAC_STAT_IPACKETS:
6150dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrcnt +
6160dc2366fSVenugopal Iyer 		    mac_rx_stat->mrs_pollcnt);
6170dc2366fSVenugopal Iyer 
6180dc2366fSVenugopal Iyer 	case MAC_STAT_RBYTES:
6190dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrbytes +
6200dc2366fSVenugopal Iyer 		    mac_rx_stat->mrs_pollbytes);
6210dc2366fSVenugopal Iyer 
6220dc2366fSVenugopal Iyer 	case MAC_STAT_INTRS:
6230dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrcnt);
6240dc2366fSVenugopal Iyer 
6250dc2366fSVenugopal Iyer 	case MAC_STAT_INTRBYTES:
6260dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrbytes);
6270dc2366fSVenugopal Iyer 
6280dc2366fSVenugopal Iyer 	case MAC_STAT_POLLS:
6290dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_pollcnt);
6300dc2366fSVenugopal Iyer 
6310dc2366fSVenugopal Iyer 	case MAC_STAT_POLLBYTES:
6320dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_pollbytes);
6330dc2366fSVenugopal Iyer 
6340dc2366fSVenugopal Iyer 	case MAC_STAT_RXSDROPS:
6350dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_sdrops);
6360dc2366fSVenugopal Iyer 
6370dc2366fSVenugopal Iyer 	case MAC_STAT_CHU10:
6380dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_chaincntundr10);
6390dc2366fSVenugopal Iyer 
6400dc2366fSVenugopal Iyer 	case MAC_STAT_CH10T50:
6410dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_chaincnt10to50);
6420dc2366fSVenugopal Iyer 
6430dc2366fSVenugopal Iyer 	case MAC_STAT_CHO50:
6440dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_chaincntover50);
6450dc2366fSVenugopal Iyer 
6460dc2366fSVenugopal Iyer 	default:
6470dc2366fSVenugopal Iyer 		return (0);
6480dc2366fSVenugopal Iyer 	}
6490dc2366fSVenugopal Iyer }
6500dc2366fSVenugopal Iyer 
6510dc2366fSVenugopal Iyer static int
i_mac_rx_hwlane_stat_update(kstat_t * ksp,int rw)6520dc2366fSVenugopal Iyer i_mac_rx_hwlane_stat_update(kstat_t *ksp, int rw)
6530dc2366fSVenugopal Iyer {
6540dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, i_mac_rx_hwlane_stat_get,
6550dc2366fSVenugopal Iyer 	    i_mac_rx_hwlane_si, MAC_RX_HWLANE_NKSTAT));
6560dc2366fSVenugopal Iyer }
6570dc2366fSVenugopal Iyer 
6580dc2366fSVenugopal Iyer static void
i_mac_rx_hwlane_stat_create(mac_soft_ring_set_t * mac_srs,const char * modname,const char * statname)6590dc2366fSVenugopal Iyer i_mac_rx_hwlane_stat_create(mac_soft_ring_set_t *mac_srs, const char *modname,
6600dc2366fSVenugopal Iyer     const char *statname)
6610dc2366fSVenugopal Iyer {
6620dc2366fSVenugopal Iyer 	kstat_t		*ksp;
6630dc2366fSVenugopal Iyer 
6640dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(mac_srs, modname, statname,
6650dc2366fSVenugopal Iyer 	    i_mac_rx_hwlane_stat_update, i_mac_rx_hwlane_si,
6660dc2366fSVenugopal Iyer 	    MAC_RX_HWLANE_NKSTAT);
6670dc2366fSVenugopal Iyer 
6680dc2366fSVenugopal Iyer 	mac_srs->srs_ksp = ksp;
6690dc2366fSVenugopal Iyer }
6700dc2366fSVenugopal Iyer 
6710dc2366fSVenugopal Iyer 
6720dc2366fSVenugopal Iyer /*
6730dc2366fSVenugopal Iyer  * Misc statistics
6740dc2366fSVenugopal Iyer  *
6750dc2366fSVenugopal Iyer  * Counts for
6760dc2366fSVenugopal Iyer  *	- Multicast/broadcast Rx/Tx counts
6770dc2366fSVenugopal Iyer  *	- Tx errors
6780dc2366fSVenugopal Iyer  */
6790dc2366fSVenugopal Iyer static uint64_t
i_mac_misc_stat_get(void * handle,uint_t stat)6800dc2366fSVenugopal Iyer i_mac_misc_stat_get(void *handle, uint_t stat)
6810dc2366fSVenugopal Iyer {
682*45948e49SRyan Zezeski 	flow_entry_t		*flent = handle;
683*45948e49SRyan Zezeski 	mac_client_impl_t	*mcip = flent->fe_mcip;
6840dc2366fSVenugopal Iyer 	mac_misc_stats_t	*mac_misc_stat = &mcip->mci_misc_stat;
6850dc2366fSVenugopal Iyer 	mac_rx_stats_t		*mac_rx_stat;
6860dc2366fSVenugopal Iyer 	mac_tx_stats_t		*mac_tx_stat;
6870dc2366fSVenugopal Iyer 
6880dc2366fSVenugopal Iyer 	mac_rx_stat = &mac_misc_stat->mms_defunctrxlanestats;
6890dc2366fSVenugopal Iyer 	mac_tx_stat = &mac_misc_stat->mms_defuncttxlanestats;
6900dc2366fSVenugopal Iyer 
6910dc2366fSVenugopal Iyer 	switch (stat) {
6920dc2366fSVenugopal Iyer 	case MAC_STAT_MULTIRCV:
6930dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_multircv);
6940dc2366fSVenugopal Iyer 
6950dc2366fSVenugopal Iyer 	case MAC_STAT_BRDCSTRCV:
6960dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_brdcstrcv);
6970dc2366fSVenugopal Iyer 
6980dc2366fSVenugopal Iyer 	case MAC_STAT_MULTIXMT:
6990dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_multixmt);
7000dc2366fSVenugopal Iyer 
7010dc2366fSVenugopal Iyer 	case MAC_STAT_BRDCSTXMT:
7020dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_brdcstxmt);
7030dc2366fSVenugopal Iyer 
7040dc2366fSVenugopal Iyer 	case MAC_STAT_MULTIRCVBYTES:
7050dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_multircvbytes);
7060dc2366fSVenugopal Iyer 
7070dc2366fSVenugopal Iyer 	case MAC_STAT_BRDCSTRCVBYTES:
7080dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_brdcstrcvbytes);
7090dc2366fSVenugopal Iyer 
7100dc2366fSVenugopal Iyer 	case MAC_STAT_MULTIXMTBYTES:
7110dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_multixmtbytes);
7120dc2366fSVenugopal Iyer 
7130dc2366fSVenugopal Iyer 	case MAC_STAT_BRDCSTXMTBYTES:
7140dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_brdcstxmtbytes);
7150dc2366fSVenugopal Iyer 
7160dc2366fSVenugopal Iyer 	case MAC_STAT_TX_ERRORS:
7170dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_txerrors);
7180dc2366fSVenugopal Iyer 
7190dc2366fSVenugopal Iyer 	case MAC_STAT_MACSPOOFED:
7200dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_macspoofed);
7210dc2366fSVenugopal Iyer 
7220dc2366fSVenugopal Iyer 	case MAC_STAT_IPSPOOFED:
7230dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_ipspoofed);
7240dc2366fSVenugopal Iyer 
7250dc2366fSVenugopal Iyer 	case MAC_STAT_DHCPSPOOFED:
7260dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_dhcpspoofed);
7270dc2366fSVenugopal Iyer 
7280dc2366fSVenugopal Iyer 	case MAC_STAT_RESTRICTED:
7290dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_restricted);
7300dc2366fSVenugopal Iyer 
7310dc2366fSVenugopal Iyer 	case MAC_STAT_DHCPDROPPED:
7320dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_dhcpdropped);
7330dc2366fSVenugopal Iyer 
7340dc2366fSVenugopal Iyer 	case MAC_STAT_IPACKETS:
7350dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrcnt +
7360dc2366fSVenugopal Iyer 		    mac_rx_stat->mrs_pollcnt);
7370dc2366fSVenugopal Iyer 
7380dc2366fSVenugopal Iyer 	case MAC_STAT_RBYTES:
7390dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrbytes +
7400dc2366fSVenugopal Iyer 		    mac_rx_stat->mrs_pollbytes);
7410dc2366fSVenugopal Iyer 
7420dc2366fSVenugopal Iyer 	case MAC_STAT_LCL:
7430dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_lclcnt);
7440dc2366fSVenugopal Iyer 
7450dc2366fSVenugopal Iyer 	case MAC_STAT_LCLBYTES:
7460dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_lclbytes);
7470dc2366fSVenugopal Iyer 
7480dc2366fSVenugopal Iyer 	case MAC_STAT_INTRS:
7490dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrcnt);
7500dc2366fSVenugopal Iyer 
7510dc2366fSVenugopal Iyer 	case MAC_STAT_INTRBYTES:
7520dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrbytes);
7530dc2366fSVenugopal Iyer 
7540dc2366fSVenugopal Iyer 	case MAC_STAT_POLLS:
7550dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_pollcnt);
7560dc2366fSVenugopal Iyer 
7570dc2366fSVenugopal Iyer 	case MAC_STAT_POLLBYTES:
7580dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_pollbytes);
7590dc2366fSVenugopal Iyer 
7600dc2366fSVenugopal Iyer 	case MAC_STAT_RXSDROPS:
7610dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_sdrops);
7620dc2366fSVenugopal Iyer 
7630dc2366fSVenugopal Iyer 	case MAC_STAT_CHU10:
7640dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_chaincntundr10);
7650dc2366fSVenugopal Iyer 
7660dc2366fSVenugopal Iyer 	case MAC_STAT_CH10T50:
7670dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_chaincnt10to50);
7680dc2366fSVenugopal Iyer 
7690dc2366fSVenugopal Iyer 	case MAC_STAT_CHO50:
7700dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_chaincntover50);
7710dc2366fSVenugopal Iyer 
7720dc2366fSVenugopal Iyer 	case MAC_STAT_OBYTES:
7730dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_obytes);
7740dc2366fSVenugopal Iyer 
7750dc2366fSVenugopal Iyer 	case MAC_STAT_OPACKETS:
7760dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_opackets);
7770dc2366fSVenugopal Iyer 
7780dc2366fSVenugopal Iyer 	case MAC_STAT_OERRORS:
7790dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_oerrors);
7800dc2366fSVenugopal Iyer 
7810dc2366fSVenugopal Iyer 	case MAC_STAT_BLOCK:
7820dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_blockcnt);
7830dc2366fSVenugopal Iyer 
7840dc2366fSVenugopal Iyer 	case MAC_STAT_UNBLOCK:
7850dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_unblockcnt);
7860dc2366fSVenugopal Iyer 
7870dc2366fSVenugopal Iyer 	case MAC_STAT_TXSDROPS:
7880dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_sdrops);
7890dc2366fSVenugopal Iyer 
7900dc2366fSVenugopal Iyer 	default:
7910dc2366fSVenugopal Iyer 		return (0);
7920dc2366fSVenugopal Iyer 	}
7930dc2366fSVenugopal Iyer }
7940dc2366fSVenugopal Iyer 
7950dc2366fSVenugopal Iyer static int
i_mac_misc_stat_update(kstat_t * ksp,int rw)7960dc2366fSVenugopal Iyer i_mac_misc_stat_update(kstat_t *ksp, int rw)
7970dc2366fSVenugopal Iyer {
7980dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, i_mac_misc_stat_get,
7990dc2366fSVenugopal Iyer 	    i_mac_misc_si, MAC_SUMMARY_NKSTAT));
8000dc2366fSVenugopal Iyer }
8010dc2366fSVenugopal Iyer 
8020dc2366fSVenugopal Iyer static void
i_mac_misc_stat_create(flow_entry_t * flent,const char * modname,const char * statname)8030dc2366fSVenugopal Iyer i_mac_misc_stat_create(flow_entry_t *flent, const char *modname,
8040dc2366fSVenugopal Iyer     const char *statname)
8050dc2366fSVenugopal Iyer {
8060dc2366fSVenugopal Iyer 	kstat_t		*ksp;
8070dc2366fSVenugopal Iyer 
8080dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(flent, modname, statname,
8090dc2366fSVenugopal Iyer 	    i_mac_misc_stat_update, i_mac_misc_si,
8100dc2366fSVenugopal Iyer 	    MAC_SUMMARY_NKSTAT);
8110dc2366fSVenugopal Iyer 
8120dc2366fSVenugopal Iyer 	flent->fe_misc_stat_ksp = ksp;
8130dc2366fSVenugopal Iyer }
8140dc2366fSVenugopal Iyer 
8150dc2366fSVenugopal Iyer /*
8160dc2366fSVenugopal Iyer  * Per hardware lane tx statistics
8170dc2366fSVenugopal Iyer  */
8180dc2366fSVenugopal Iyer static uint64_t
i_mac_tx_hwlane_stat_get(void * handle,uint_t stat)8190dc2366fSVenugopal Iyer i_mac_tx_hwlane_stat_get(void *handle, uint_t stat)
8200dc2366fSVenugopal Iyer {
8210dc2366fSVenugopal Iyer 	mac_soft_ring_t	*ringp = (mac_soft_ring_t *)handle;
8220dc2366fSVenugopal Iyer 	mac_tx_stats_t	*mac_tx_stat = &ringp->s_st_stat;
8230dc2366fSVenugopal Iyer 
8240dc2366fSVenugopal Iyer 	switch (stat) {
8250dc2366fSVenugopal Iyer 	case MAC_STAT_OBYTES:
8260dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_obytes);
8270dc2366fSVenugopal Iyer 
8280dc2366fSVenugopal Iyer 	case MAC_STAT_OPACKETS:
8290dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_opackets);
8300dc2366fSVenugopal Iyer 
8310dc2366fSVenugopal Iyer 	case MAC_STAT_OERRORS:
8320dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_oerrors);
8330dc2366fSVenugopal Iyer 
8340dc2366fSVenugopal Iyer 	case MAC_STAT_BLOCK:
8350dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_blockcnt);
8360dc2366fSVenugopal Iyer 
8370dc2366fSVenugopal Iyer 	case MAC_STAT_UNBLOCK:
8380dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_unblockcnt);
8390dc2366fSVenugopal Iyer 
8400dc2366fSVenugopal Iyer 	case MAC_STAT_TXSDROPS:
8410dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_sdrops);
8420dc2366fSVenugopal Iyer 
8430dc2366fSVenugopal Iyer 	default:
8440dc2366fSVenugopal Iyer 		return (0);
8450dc2366fSVenugopal Iyer 	}
8460dc2366fSVenugopal Iyer }
8470dc2366fSVenugopal Iyer 
8480dc2366fSVenugopal Iyer static int
i_mac_tx_hwlane_stat_update(kstat_t * ksp,int rw)8490dc2366fSVenugopal Iyer i_mac_tx_hwlane_stat_update(kstat_t *ksp, int rw)
8500dc2366fSVenugopal Iyer {
8510dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, i_mac_tx_hwlane_stat_get,
8520dc2366fSVenugopal Iyer 	    i_mac_tx_hwlane_si, MAC_TX_HWLANE_NKSTAT));
8530dc2366fSVenugopal Iyer }
8540dc2366fSVenugopal Iyer 
8550dc2366fSVenugopal Iyer static void
i_mac_tx_hwlane_stat_create(mac_soft_ring_t * ringp,const char * modname,const char * statname)8560dc2366fSVenugopal Iyer i_mac_tx_hwlane_stat_create(mac_soft_ring_t *ringp, const char *modname,
8570dc2366fSVenugopal Iyer     const char *statname)
8580dc2366fSVenugopal Iyer {
8590dc2366fSVenugopal Iyer 	kstat_t		*ksp;
8600dc2366fSVenugopal Iyer 
8610dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(ringp, modname, statname,
8620dc2366fSVenugopal Iyer 	    i_mac_tx_hwlane_stat_update, i_mac_tx_hwlane_si,
8630dc2366fSVenugopal Iyer 	    MAC_TX_HWLANE_NKSTAT);
8640dc2366fSVenugopal Iyer 
8650dc2366fSVenugopal Iyer 	ringp->s_ring_ksp = ksp;
8660dc2366fSVenugopal Iyer }
8670dc2366fSVenugopal Iyer 
8680dc2366fSVenugopal Iyer /*
8690dc2366fSVenugopal Iyer  * Per fanout rx statistics
8700dc2366fSVenugopal Iyer  */
8710dc2366fSVenugopal Iyer static uint64_t
i_mac_rx_fanout_stat_get(void * handle,uint_t stat)8720dc2366fSVenugopal Iyer i_mac_rx_fanout_stat_get(void *handle, uint_t stat)
8730dc2366fSVenugopal Iyer {
874*45948e49SRyan Zezeski 	mac_soft_ring_t		*tcp_ringp = (mac_soft_ring_t *)handle;
8750dc2366fSVenugopal Iyer 	mac_soft_ring_t		*udp_ringp = NULL, *oth_ringp = NULL;
876*45948e49SRyan Zezeski 	mac_soft_ring_set_t	*mac_srs = tcp_ringp->s_ring_set;
8770dc2366fSVenugopal Iyer 	int			index;
8780dc2366fSVenugopal Iyer 	uint64_t		val;
8790dc2366fSVenugopal Iyer 
8800dc2366fSVenugopal Iyer 	mutex_enter(&mac_srs->srs_lock);
8810dc2366fSVenugopal Iyer 	/* Extract corresponding udp and oth ring pointers */
8820dc2366fSVenugopal Iyer 	for (index = 0; mac_srs->srs_tcp_soft_rings[index] != NULL; index++) {
8830dc2366fSVenugopal Iyer 		if (mac_srs->srs_tcp_soft_rings[index] == tcp_ringp) {
8840dc2366fSVenugopal Iyer 			udp_ringp = mac_srs->srs_udp_soft_rings[index];
8850dc2366fSVenugopal Iyer 			oth_ringp = mac_srs->srs_oth_soft_rings[index];
8860dc2366fSVenugopal Iyer 			break;
8870dc2366fSVenugopal Iyer 		}
8880dc2366fSVenugopal Iyer 	}
8890dc2366fSVenugopal Iyer 
8900dc2366fSVenugopal Iyer 	ASSERT((udp_ringp != NULL) && (oth_ringp != NULL));
8910dc2366fSVenugopal Iyer 
8920dc2366fSVenugopal Iyer 	switch (stat) {
8930dc2366fSVenugopal Iyer 	case MAC_STAT_RBYTES:
8940dc2366fSVenugopal Iyer 		val = (tcp_ringp->s_ring_total_rbytes) +
8950dc2366fSVenugopal Iyer 		    (udp_ringp->s_ring_total_rbytes) +
8960dc2366fSVenugopal Iyer 		    (oth_ringp->s_ring_total_rbytes);
8970dc2366fSVenugopal Iyer 		break;
8980dc2366fSVenugopal Iyer 
8990dc2366fSVenugopal Iyer 	case MAC_STAT_IPACKETS:
9000dc2366fSVenugopal Iyer 		val = (tcp_ringp->s_ring_total_inpkt) +
9010dc2366fSVenugopal Iyer 		    (udp_ringp->s_ring_total_inpkt) +
9020dc2366fSVenugopal Iyer 		    (oth_ringp->s_ring_total_inpkt);
9030dc2366fSVenugopal Iyer 		break;
9040dc2366fSVenugopal Iyer 
9050dc2366fSVenugopal Iyer 	default:
9060dc2366fSVenugopal Iyer 		val = 0;
9070dc2366fSVenugopal Iyer 		break;
9080dc2366fSVenugopal Iyer 	}
9090dc2366fSVenugopal Iyer 	mutex_exit(&mac_srs->srs_lock);
9100dc2366fSVenugopal Iyer 	return (val);
9110dc2366fSVenugopal Iyer }
9120dc2366fSVenugopal Iyer 
9130dc2366fSVenugopal Iyer static int
i_mac_rx_fanout_stat_update(kstat_t * ksp,int rw)9140dc2366fSVenugopal Iyer i_mac_rx_fanout_stat_update(kstat_t *ksp, int rw)
9150dc2366fSVenugopal Iyer {
9160dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, i_mac_rx_fanout_stat_get,
9170dc2366fSVenugopal Iyer 	    i_mac_rx_fanout_si, MAC_RX_FANOUT_NKSTAT));
9180dc2366fSVenugopal Iyer }
9190dc2366fSVenugopal Iyer 
9200dc2366fSVenugopal Iyer static void
i_mac_rx_fanout_stat_create(mac_soft_ring_t * ringp,const char * modname,const char * statname)9210dc2366fSVenugopal Iyer i_mac_rx_fanout_stat_create(mac_soft_ring_t *ringp, const char *modname,
9220dc2366fSVenugopal Iyer     const char *statname)
9230dc2366fSVenugopal Iyer {
9240dc2366fSVenugopal Iyer 	kstat_t		*ksp;
9250dc2366fSVenugopal Iyer 
9260dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(ringp, modname, statname,
9270dc2366fSVenugopal Iyer 	    i_mac_rx_fanout_stat_update, i_mac_rx_fanout_si,
9280dc2366fSVenugopal Iyer 	    MAC_RX_FANOUT_NKSTAT);
9290dc2366fSVenugopal Iyer 
9300dc2366fSVenugopal Iyer 	ringp->s_ring_ksp = ksp;
9310dc2366fSVenugopal Iyer }
9320dc2366fSVenugopal Iyer 
9337c478bd9Sstevel@tonic-gate /*
9347c478bd9Sstevel@tonic-gate  * Exported functions.
9357c478bd9Sstevel@tonic-gate  */
9367c478bd9Sstevel@tonic-gate 
937ba2e4443Sseb /*
938ba2e4443Sseb  * Create the "mac" kstat.  The "mac" kstat is comprised of three kinds of
939ba2e4443Sseb  * statistics: statistics maintained by the mac module itself, generic mac
940ba2e4443Sseb  * statistics maintained by the driver, and MAC-type specific statistics
941ba2e4443Sseb  * also maintained by the driver.
942ba2e4443Sseb  */
9437c478bd9Sstevel@tonic-gate void
mac_driver_stat_create(mac_impl_t * mip)9440dc2366fSVenugopal Iyer mac_driver_stat_create(mac_impl_t *mip)
9457c478bd9Sstevel@tonic-gate {
9467c478bd9Sstevel@tonic-gate 	kstat_t		*ksp;
9477c478bd9Sstevel@tonic-gate 	kstat_named_t	*knp;
9487c478bd9Sstevel@tonic-gate 	uint_t		count;
949d62bc4baSyz 	major_t		major = getmajor(mip->mi_phy_dev);
9507c478bd9Sstevel@tonic-gate 
951ba2e4443Sseb 	count = MAC_MOD_NKSTAT + MAC_NKSTAT + mip->mi_type->mt_statcount;
95261af1958SGarrett D'Amore 	ksp = kstat_create((const char *)ddi_major_to_name(major),
95361af1958SGarrett D'Amore 	    getminor(mip->mi_phy_dev) - 1, MAC_KSTAT_NAME,
95461af1958SGarrett D'Amore 	    MAC_KSTAT_CLASS, KSTAT_TYPE_NAMED, count, 0);
955ba2e4443Sseb 	if (ksp == NULL)
9567c478bd9Sstevel@tonic-gate 		return;
9577c478bd9Sstevel@tonic-gate 
9580dc2366fSVenugopal Iyer 	ksp->ks_update = i_mac_driver_stat_update;
959ba2e4443Sseb 	ksp->ks_private = mip;
9607c478bd9Sstevel@tonic-gate 	mip->mi_ksp = ksp;
961ba2e4443Sseb 	mip->mi_kstat_count = count;
9627c478bd9Sstevel@tonic-gate 
9637c478bd9Sstevel@tonic-gate 	knp = (kstat_named_t *)ksp->ks_data;
964ba2e4443Sseb 	i_mac_kstat_init(knp, i_mac_mod_si, MAC_MOD_NKSTAT);
965ba2e4443Sseb 	knp += MAC_MOD_NKSTAT;
966ba2e4443Sseb 	i_mac_kstat_init(knp, i_mac_si, MAC_NKSTAT);
967ba2e4443Sseb 	if (mip->mi_type->mt_statcount > 0) {
968ba2e4443Sseb 		knp += MAC_NKSTAT;
969ba2e4443Sseb 		i_mac_kstat_init(knp, mip->mi_type->mt_stats,
970ba2e4443Sseb 		    mip->mi_type->mt_statcount);
9717c478bd9Sstevel@tonic-gate 	}
9727c478bd9Sstevel@tonic-gate 
9737c478bd9Sstevel@tonic-gate 	kstat_install(ksp);
9747c478bd9Sstevel@tonic-gate }
9757c478bd9Sstevel@tonic-gate 
9767c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9777c478bd9Sstevel@tonic-gate void
mac_driver_stat_delete(mac_impl_t * mip)9780dc2366fSVenugopal Iyer mac_driver_stat_delete(mac_impl_t *mip)
9797c478bd9Sstevel@tonic-gate {
980ba2e4443Sseb 	if (mip->mi_ksp != NULL) {
981ba2e4443Sseb 		kstat_delete(mip->mi_ksp);
982ba2e4443Sseb 		mip->mi_ksp = NULL;
983ba2e4443Sseb 		mip->mi_kstat_count = 0;
984ba2e4443Sseb 	}
985ba2e4443Sseb }
986ba2e4443Sseb 
987ba2e4443Sseb uint64_t
mac_driver_stat_default(mac_impl_t * mip,uint_t stat)9880dc2366fSVenugopal Iyer mac_driver_stat_default(mac_impl_t *mip, uint_t stat)
989ba2e4443Sseb {
990ba2e4443Sseb 	uint_t	stat_index;
991ba2e4443Sseb 
992ba2e4443Sseb 	if (IS_MAC_STAT(stat)) {
993ba2e4443Sseb 		stat_index = stat - MAC_STAT_MIN;
9940dc2366fSVenugopal Iyer 		ASSERT(stat_index < MAC_NKSTAT);
995ba2e4443Sseb 		return (i_mac_si[stat_index].msi_default);
996ba2e4443Sseb 	}
997ba2e4443Sseb 	ASSERT(IS_MACTYPE_STAT(stat));
998ba2e4443Sseb 	stat_index = stat - MACTYPE_STAT_MIN;
9990dc2366fSVenugopal Iyer 	ASSERT(stat_index < mip->mi_type->mt_statcount);
1000ba2e4443Sseb 	return (mip->mi_type->mt_stats[stat_index].msi_default);
10017c478bd9Sstevel@tonic-gate }
10020dc2366fSVenugopal Iyer 
10030dc2366fSVenugopal Iyer void
mac_ring_stat_create(mac_ring_t * ring)10040dc2366fSVenugopal Iyer mac_ring_stat_create(mac_ring_t *ring)
10050dc2366fSVenugopal Iyer {
10060dc2366fSVenugopal Iyer 	mac_impl_t	*mip = ring->mr_mip;
1007*45948e49SRyan Zezeski 	mac_group_t	*grp = (mac_group_t *)ring->mr_gh;
10080dc2366fSVenugopal Iyer 	char		statname[MAXNAMELEN];
10090dc2366fSVenugopal Iyer 	char		modname[MAXNAMELEN];
10100dc2366fSVenugopal Iyer 
10110dc2366fSVenugopal Iyer 	if (mip->mi_state_flags & MIS_IS_AGGR) {
10120dc2366fSVenugopal Iyer 		(void) strlcpy(modname, mip->mi_clients_list->mci_name,
10130dc2366fSVenugopal Iyer 		    MAXNAMELEN);
10140dc2366fSVenugopal Iyer 	} else
10150dc2366fSVenugopal Iyer 		(void) strlcpy(modname, mip->mi_name, MAXNAMELEN);
10160dc2366fSVenugopal Iyer 
10170dc2366fSVenugopal Iyer 	switch (ring->mr_type) {
10180dc2366fSVenugopal Iyer 	case MAC_RING_TYPE_RX:
1019*45948e49SRyan Zezeski 		(void) snprintf(statname, sizeof (statname),
1020*45948e49SRyan Zezeski 		    "mac_rx_ring_%d_%d", grp->mrg_index, ring->mr_index);
10210dc2366fSVenugopal Iyer 		i_mac_rx_ring_stat_create(ring, modname, statname);
10220dc2366fSVenugopal Iyer 		break;
10230dc2366fSVenugopal Iyer 
10240dc2366fSVenugopal Iyer 	case MAC_RING_TYPE_TX:
10250dc2366fSVenugopal Iyer 		(void) snprintf(statname, sizeof (statname), "mac_tx_ring%d",
10260dc2366fSVenugopal Iyer 		    ring->mr_index);
10270dc2366fSVenugopal Iyer 		i_mac_tx_ring_stat_create(ring, modname, statname);
10280dc2366fSVenugopal Iyer 		break;
10290dc2366fSVenugopal Iyer 
10300dc2366fSVenugopal Iyer 	default:
10310dc2366fSVenugopal Iyer 		ASSERT(B_FALSE);
10320dc2366fSVenugopal Iyer 		break;
10330dc2366fSVenugopal Iyer 	}
10340dc2366fSVenugopal Iyer }
10350dc2366fSVenugopal Iyer 
10360dc2366fSVenugopal Iyer void
mac_srs_stat_create(mac_soft_ring_set_t * mac_srs)10370dc2366fSVenugopal Iyer mac_srs_stat_create(mac_soft_ring_set_t *mac_srs)
10380dc2366fSVenugopal Iyer {
10390dc2366fSVenugopal Iyer 	flow_entry_t	*flent = mac_srs->srs_flent;
1040*45948e49SRyan Zezeski 	char		statname[MAXNAMELEN];
10410dc2366fSVenugopal Iyer 	boolean_t	is_tx_srs;
10420dc2366fSVenugopal Iyer 
10430dc2366fSVenugopal Iyer 	/* No hardware/software lanes for user defined flows */
10440dc2366fSVenugopal Iyer 	if ((flent->fe_type & FLOW_USER) != 0)
10450dc2366fSVenugopal Iyer 		return;
10460dc2366fSVenugopal Iyer 
10470dc2366fSVenugopal Iyer 	is_tx_srs = ((mac_srs->srs_type & SRST_TX) != 0);
10480dc2366fSVenugopal Iyer 
10490dc2366fSVenugopal Iyer 	if (is_tx_srs) {
10500dc2366fSVenugopal Iyer 		mac_srs_tx_t	*srs_tx = &mac_srs->srs_tx;
10510dc2366fSVenugopal Iyer 		mac_ring_t	*ring = srs_tx->st_arg2;
10520dc2366fSVenugopal Iyer 
10530dc2366fSVenugopal Iyer 		if (ring != NULL) {
10540dc2366fSVenugopal Iyer 			(void) snprintf(statname, sizeof (statname),
10550dc2366fSVenugopal Iyer 			    "mac_tx_hwlane%d", ring->mr_index);
10560dc2366fSVenugopal Iyer 		} else {
10570dc2366fSVenugopal Iyer 			(void) snprintf(statname, sizeof (statname),
10580dc2366fSVenugopal Iyer 			    "mac_tx_swlane0");
10590dc2366fSVenugopal Iyer 		}
10600dc2366fSVenugopal Iyer 		i_mac_tx_swlane_stat_create(mac_srs, flent->fe_flow_name,
10610dc2366fSVenugopal Iyer 		    statname);
10620dc2366fSVenugopal Iyer 	} else {
10630dc2366fSVenugopal Iyer 		mac_ring_t	*ring = mac_srs->srs_ring;
10640dc2366fSVenugopal Iyer 
10650dc2366fSVenugopal Iyer 		if (ring == NULL) {
10660dc2366fSVenugopal Iyer 			(void) snprintf(statname, sizeof (statname),
10670dc2366fSVenugopal Iyer 			    "mac_rx_swlane0");
10680dc2366fSVenugopal Iyer 			i_mac_rx_swlane_stat_create(mac_srs,
10690dc2366fSVenugopal Iyer 			    flent->fe_flow_name, statname);
10700dc2366fSVenugopal Iyer 		} else {
10710dc2366fSVenugopal Iyer 			(void) snprintf(statname, sizeof (statname),
10720dc2366fSVenugopal Iyer 			    "mac_rx_hwlane%d", ring->mr_index);
10730dc2366fSVenugopal Iyer 			i_mac_rx_hwlane_stat_create(mac_srs,
10740dc2366fSVenugopal Iyer 			    flent->fe_flow_name, statname);
10750dc2366fSVenugopal Iyer 		}
10760dc2366fSVenugopal Iyer 	}
10770dc2366fSVenugopal Iyer }
10780dc2366fSVenugopal Iyer 
10790dc2366fSVenugopal Iyer void
mac_misc_stat_create(flow_entry_t * flent)10800dc2366fSVenugopal Iyer mac_misc_stat_create(flow_entry_t *flent)
10810dc2366fSVenugopal Iyer {
10820dc2366fSVenugopal Iyer 	char	statname[MAXNAMELEN];
10830dc2366fSVenugopal Iyer 
10840dc2366fSVenugopal Iyer 	/* No misc stats for user defined or mcast/bcast flows */
10850dc2366fSVenugopal Iyer 	if (((flent->fe_type & FLOW_USER) != 0) ||
10860dc2366fSVenugopal Iyer 	    ((flent->fe_type & FLOW_MCAST) != 0))
10870dc2366fSVenugopal Iyer 		return;
10880dc2366fSVenugopal Iyer 
10890dc2366fSVenugopal Iyer 	(void) snprintf(statname, sizeof (statname), "mac_misc_stat");
10900dc2366fSVenugopal Iyer 	i_mac_misc_stat_create(flent, flent->fe_flow_name, statname);
10910dc2366fSVenugopal Iyer }
10920dc2366fSVenugopal Iyer 
10930dc2366fSVenugopal Iyer void
mac_soft_ring_stat_create(mac_soft_ring_t * ringp)10940dc2366fSVenugopal Iyer mac_soft_ring_stat_create(mac_soft_ring_t *ringp)
10950dc2366fSVenugopal Iyer {
10960dc2366fSVenugopal Iyer 	mac_soft_ring_set_t	*mac_srs = ringp->s_ring_set;
10970dc2366fSVenugopal Iyer 	flow_entry_t		*flent = ringp->s_ring_mcip->mci_flent;
10980dc2366fSVenugopal Iyer 	mac_ring_t		*ring = (mac_ring_t *)ringp->s_ring_tx_arg2;
10990dc2366fSVenugopal Iyer 	boolean_t		is_tx_srs;
11000dc2366fSVenugopal Iyer 	char			statname[MAXNAMELEN];
11010dc2366fSVenugopal Iyer 
11020dc2366fSVenugopal Iyer 	/* No hardware/software lanes for user defined flows */
11030dc2366fSVenugopal Iyer 	if ((flent->fe_type & FLOW_USER) != 0)
11040dc2366fSVenugopal Iyer 		return;
11050dc2366fSVenugopal Iyer 
11060dc2366fSVenugopal Iyer 	is_tx_srs = ((mac_srs->srs_type & SRST_TX) != 0);
11070dc2366fSVenugopal Iyer 	if (is_tx_srs) {	/* tx side hardware lane */
11080dc2366fSVenugopal Iyer 		ASSERT(ring != NULL);
11090dc2366fSVenugopal Iyer 		(void) snprintf(statname, sizeof (statname), "mac_tx_hwlane%d",
11100dc2366fSVenugopal Iyer 		    ring->mr_index);
11110dc2366fSVenugopal Iyer 		i_mac_tx_hwlane_stat_create(ringp, flent->fe_flow_name,
11120dc2366fSVenugopal Iyer 		    statname);
11130dc2366fSVenugopal Iyer 	} else {		/* rx side fanout */
11140dc2366fSVenugopal Iyer 				/* Maintain single stat for (tcp, udp, oth) */
11150dc2366fSVenugopal Iyer 		if (ringp->s_ring_type & ST_RING_TCP) {
11160dc2366fSVenugopal Iyer 			int			index;
11170dc2366fSVenugopal Iyer 			mac_soft_ring_t		*softring;
11180dc2366fSVenugopal Iyer 
11190dc2366fSVenugopal Iyer 			for (index = 0, softring = mac_srs->srs_soft_ring_head;
11200dc2366fSVenugopal Iyer 			    softring != NULL;
11210dc2366fSVenugopal Iyer 			    index++, softring = softring->s_ring_next) {
11220dc2366fSVenugopal Iyer 				if (softring == ringp)
11230dc2366fSVenugopal Iyer 					break;
11240dc2366fSVenugopal Iyer 			}
11250dc2366fSVenugopal Iyer 
11260dc2366fSVenugopal Iyer 			if (mac_srs->srs_ring == NULL) {
11270dc2366fSVenugopal Iyer 				(void) snprintf(statname, sizeof (statname),
11280dc2366fSVenugopal Iyer 				    "mac_rx_swlane0_fanout%d", index/3);
11290dc2366fSVenugopal Iyer 			} else {
11300dc2366fSVenugopal Iyer 				(void) snprintf(statname, sizeof (statname),
11310dc2366fSVenugopal Iyer 				    "mac_rx_hwlane%d_fanout%d",
11320dc2366fSVenugopal Iyer 				    mac_srs->srs_ring->mr_index, index/3);
11330dc2366fSVenugopal Iyer 			}
11340dc2366fSVenugopal Iyer 			i_mac_rx_fanout_stat_create(ringp, flent->fe_flow_name,
11350dc2366fSVenugopal Iyer 			    statname);
11360dc2366fSVenugopal Iyer 		}
11370dc2366fSVenugopal Iyer 	}
11380dc2366fSVenugopal Iyer }
11390dc2366fSVenugopal Iyer 
11400dc2366fSVenugopal Iyer void
mac_ring_stat_delete(mac_ring_t * ring)11410dc2366fSVenugopal Iyer mac_ring_stat_delete(mac_ring_t *ring)
11420dc2366fSVenugopal Iyer {
11430dc2366fSVenugopal Iyer 	if (ring->mr_ksp != NULL) {
11440dc2366fSVenugopal Iyer 		kstat_delete(ring->mr_ksp);
11450dc2366fSVenugopal Iyer 		ring->mr_ksp = NULL;
11460dc2366fSVenugopal Iyer 	}
11470dc2366fSVenugopal Iyer }
11480dc2366fSVenugopal Iyer 
11490dc2366fSVenugopal Iyer void
mac_srs_stat_delete(mac_soft_ring_set_t * mac_srs)11500dc2366fSVenugopal Iyer mac_srs_stat_delete(mac_soft_ring_set_t *mac_srs)
11510dc2366fSVenugopal Iyer {
11520dc2366fSVenugopal Iyer 	boolean_t	is_tx_srs;
11530dc2366fSVenugopal Iyer 
11540dc2366fSVenugopal Iyer 	is_tx_srs = ((mac_srs->srs_type & SRST_TX) != 0);
11550dc2366fSVenugopal Iyer 	if (!is_tx_srs) {
11560dc2366fSVenugopal Iyer 		/*
11570dc2366fSVenugopal Iyer 		 * Rx ring has been taken away. Before destroying corresponding
11580dc2366fSVenugopal Iyer 		 * SRS, save the stats recorded by that SRS.
11590dc2366fSVenugopal Iyer 		 */
11600dc2366fSVenugopal Iyer 		mac_client_impl_t	*mcip = mac_srs->srs_mcip;
11610dc2366fSVenugopal Iyer 		mac_misc_stats_t	*mac_misc_stat = &mcip->mci_misc_stat;
11620dc2366fSVenugopal Iyer 		mac_rx_stats_t		*mac_rx_stat = &mac_srs->srs_rx.sr_stat;
11630dc2366fSVenugopal Iyer 
11640dc2366fSVenugopal Iyer 		i_mac_add_stats(&mac_misc_stat->mms_defunctrxlanestats,
11650dc2366fSVenugopal Iyer 		    mac_rx_stat, &mac_misc_stat->mms_defunctrxlanestats,
11660dc2366fSVenugopal Iyer 		    rx_srs_stats_list, RX_SRS_STAT_SIZE);
11670dc2366fSVenugopal Iyer 	}
11680dc2366fSVenugopal Iyer 
11690dc2366fSVenugopal Iyer 	if (mac_srs->srs_ksp != NULL) {
11700dc2366fSVenugopal Iyer 		kstat_delete(mac_srs->srs_ksp);
11710dc2366fSVenugopal Iyer 		mac_srs->srs_ksp = NULL;
11720dc2366fSVenugopal Iyer 	}
11730dc2366fSVenugopal Iyer }
11740dc2366fSVenugopal Iyer 
11750dc2366fSVenugopal Iyer void
mac_misc_stat_delete(flow_entry_t * flent)11760dc2366fSVenugopal Iyer mac_misc_stat_delete(flow_entry_t *flent)
11770dc2366fSVenugopal Iyer {
11780dc2366fSVenugopal Iyer 	if (flent->fe_misc_stat_ksp != NULL) {
11790dc2366fSVenugopal Iyer 		kstat_delete(flent->fe_misc_stat_ksp);
11800dc2366fSVenugopal Iyer 		flent->fe_misc_stat_ksp = NULL;
11810dc2366fSVenugopal Iyer 	}
11820dc2366fSVenugopal Iyer }
11830dc2366fSVenugopal Iyer 
11840dc2366fSVenugopal Iyer void
mac_soft_ring_stat_delete(mac_soft_ring_t * ringp)11850dc2366fSVenugopal Iyer mac_soft_ring_stat_delete(mac_soft_ring_t *ringp)
11860dc2366fSVenugopal Iyer {
11870dc2366fSVenugopal Iyer 	mac_soft_ring_set_t	*mac_srs = ringp->s_ring_set;
11880dc2366fSVenugopal Iyer 	boolean_t		is_tx_srs;
11890dc2366fSVenugopal Iyer 
11900dc2366fSVenugopal Iyer 	is_tx_srs = ((mac_srs->srs_type & SRST_TX) != 0);
11910dc2366fSVenugopal Iyer 	if (is_tx_srs) {
11920dc2366fSVenugopal Iyer 		/*
11930dc2366fSVenugopal Iyer 		 * Tx ring has been taken away. Before destroying corresponding
11940dc2366fSVenugopal Iyer 		 * soft ring, save the stats recorded by that soft ring.
11950dc2366fSVenugopal Iyer 		 */
11960dc2366fSVenugopal Iyer 		mac_client_impl_t	*mcip = mac_srs->srs_mcip;
11970dc2366fSVenugopal Iyer 		mac_misc_stats_t	*mac_misc_stat = &mcip->mci_misc_stat;
11980dc2366fSVenugopal Iyer 		mac_tx_stats_t		*mac_tx_stat = &ringp->s_st_stat;
11990dc2366fSVenugopal Iyer 
12000dc2366fSVenugopal Iyer 		i_mac_add_stats(&mac_misc_stat->mms_defuncttxlanestats,
12010dc2366fSVenugopal Iyer 		    mac_tx_stat, &mac_misc_stat->mms_defuncttxlanestats,
12020dc2366fSVenugopal Iyer 		    tx_softring_stats_list, TX_SOFTRING_STAT_SIZE);
12030dc2366fSVenugopal Iyer 	}
12040dc2366fSVenugopal Iyer 
12050dc2366fSVenugopal Iyer 	if (ringp->s_ring_ksp) {
12060dc2366fSVenugopal Iyer 		kstat_delete(ringp->s_ring_ksp);
12070dc2366fSVenugopal Iyer 		ringp->s_ring_ksp = NULL;
12080dc2366fSVenugopal Iyer 	}
12090dc2366fSVenugopal Iyer }
12100dc2366fSVenugopal Iyer 
12110dc2366fSVenugopal Iyer void
mac_pseudo_ring_stat_rename(mac_impl_t * mip)12120dc2366fSVenugopal Iyer mac_pseudo_ring_stat_rename(mac_impl_t *mip)
12130dc2366fSVenugopal Iyer {
12140dc2366fSVenugopal Iyer 	mac_group_t	*group;
12150dc2366fSVenugopal Iyer 	mac_ring_t	*ring;
12160dc2366fSVenugopal Iyer 
12170dc2366fSVenugopal Iyer 	/* Recreate pseudo rx ring kstats */
12180dc2366fSVenugopal Iyer 	for (group = mip->mi_rx_groups; group != NULL;
12190dc2366fSVenugopal Iyer 	    group = group->mrg_next) {
12200dc2366fSVenugopal Iyer 		for (ring = group->mrg_rings; ring != NULL;
12210dc2366fSVenugopal Iyer 		    ring = ring->mr_next) {
12220dc2366fSVenugopal Iyer 			mac_ring_stat_delete(ring);
12230dc2366fSVenugopal Iyer 			mac_ring_stat_create(ring);
12240dc2366fSVenugopal Iyer 		}
12250dc2366fSVenugopal Iyer 	}
12260dc2366fSVenugopal Iyer 
12270dc2366fSVenugopal Iyer 	/* Recreate pseudo tx ring kstats */
12280dc2366fSVenugopal Iyer 	for (group = mip->mi_tx_groups; group != NULL;
12290dc2366fSVenugopal Iyer 	    group = group->mrg_next) {
12300dc2366fSVenugopal Iyer 		for (ring = group->mrg_rings; ring != NULL;
12310dc2366fSVenugopal Iyer 		    ring = ring->mr_next) {
12320dc2366fSVenugopal Iyer 			mac_ring_stat_delete(ring);
12330dc2366fSVenugopal Iyer 			mac_ring_stat_create(ring);
12340dc2366fSVenugopal Iyer 		}
12350dc2366fSVenugopal Iyer 	}
12360dc2366fSVenugopal Iyer }
12370dc2366fSVenugopal Iyer 
12380dc2366fSVenugopal Iyer void
mac_stat_rename(mac_client_impl_t * mcip)12390dc2366fSVenugopal Iyer mac_stat_rename(mac_client_impl_t *mcip)
12400dc2366fSVenugopal Iyer {
12410dc2366fSVenugopal Iyer 	flow_entry_t		*flent = mcip->mci_flent;
12420dc2366fSVenugopal Iyer 	mac_soft_ring_set_t	*mac_srs;
12430dc2366fSVenugopal Iyer 	mac_soft_ring_t		*ringp;
12440dc2366fSVenugopal Iyer 	int			i, j;
12450dc2366fSVenugopal Iyer 
12460dc2366fSVenugopal Iyer 	ASSERT(flent != NULL);
12470dc2366fSVenugopal Iyer 
12480dc2366fSVenugopal Iyer 	/* Recreate rx SRSes kstats */
12490dc2366fSVenugopal Iyer 	for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
12500dc2366fSVenugopal Iyer 		mac_srs = (mac_soft_ring_set_t *)flent->fe_rx_srs[i];
12510dc2366fSVenugopal Iyer 		mac_srs_stat_delete(mac_srs);
12520dc2366fSVenugopal Iyer 		mac_srs_stat_create(mac_srs);
12530dc2366fSVenugopal Iyer 
12540dc2366fSVenugopal Iyer 		/* Recreate rx fanout kstats */
12550dc2366fSVenugopal Iyer 		for (j = 0; j < mac_srs->srs_tcp_ring_count; j++) {
12560dc2366fSVenugopal Iyer 			ringp = mac_srs->srs_tcp_soft_rings[j];
12570dc2366fSVenugopal Iyer 			mac_soft_ring_stat_delete(ringp);
12580dc2366fSVenugopal Iyer 			mac_soft_ring_stat_create(ringp);
12590dc2366fSVenugopal Iyer 		}
12600dc2366fSVenugopal Iyer 	}
12610dc2366fSVenugopal Iyer 
12620dc2366fSVenugopal Iyer 	/* Recreate tx SRS kstats */
12630dc2366fSVenugopal Iyer 	mac_srs = (mac_soft_ring_set_t *)flent->fe_tx_srs;
12640dc2366fSVenugopal Iyer 	mac_srs_stat_delete(mac_srs);
12650dc2366fSVenugopal Iyer 	mac_srs_stat_create(mac_srs);
12660dc2366fSVenugopal Iyer 
12670dc2366fSVenugopal Iyer 	/* Recreate tx sofring kstats */
12680dc2366fSVenugopal Iyer 	for (ringp = mac_srs->srs_soft_ring_head; ringp;
12690dc2366fSVenugopal Iyer 	    ringp = ringp->s_ring_next) {
12700dc2366fSVenugopal Iyer 		mac_soft_ring_stat_delete(ringp);
12710dc2366fSVenugopal Iyer 		mac_soft_ring_stat_create(ringp);
12720dc2366fSVenugopal Iyer 	}
12730dc2366fSVenugopal Iyer 
12740dc2366fSVenugopal Iyer 	/* Recreate misc kstats */
12750dc2366fSVenugopal Iyer 	mac_misc_stat_delete(flent);
12760dc2366fSVenugopal Iyer 	mac_misc_stat_create(flent);
12770dc2366fSVenugopal Iyer }
12780dc2366fSVenugopal Iyer 
12790dc2366fSVenugopal Iyer void
mac_tx_srs_stat_recreate(mac_soft_ring_set_t * tx_srs,boolean_t add_stats)12800dc2366fSVenugopal Iyer mac_tx_srs_stat_recreate(mac_soft_ring_set_t *tx_srs, boolean_t add_stats)
12810dc2366fSVenugopal Iyer {
12820dc2366fSVenugopal Iyer 	mac_client_impl_t	*mcip = tx_srs->srs_mcip;
12830dc2366fSVenugopal Iyer 	mac_misc_stats_t	*mac_misc_stat = &mcip->mci_misc_stat;
12840dc2366fSVenugopal Iyer 	mac_tx_stats_t		*mac_tx_stat = &tx_srs->srs_tx.st_stat;
12850dc2366fSVenugopal Iyer 
12860dc2366fSVenugopal Iyer 	if (add_stats) {
12870dc2366fSVenugopal Iyer 		/* Add the stats to cumulative stats */
12880dc2366fSVenugopal Iyer 		i_mac_add_stats(&mac_misc_stat->mms_defuncttxlanestats,
12890dc2366fSVenugopal Iyer 		    mac_tx_stat, &mac_misc_stat->mms_defuncttxlanestats,
12900dc2366fSVenugopal Iyer 		    tx_softring_stats_list, TX_SOFTRING_STAT_SIZE);
12910dc2366fSVenugopal Iyer 	}
12920dc2366fSVenugopal Iyer 
12930dc2366fSVenugopal Iyer 	bzero(mac_tx_stat, sizeof (mac_tx_stats_t));
12940dc2366fSVenugopal Iyer 	mac_srs_stat_delete(tx_srs);
12950dc2366fSVenugopal Iyer 	mac_srs_stat_create(tx_srs);
12960dc2366fSVenugopal Iyer }
1297