xref: /titanic_52/usr/src/uts/common/io/mac/mac_stat.c (revision 0dc2366f7b9f9f36e10909b1e95edbf2a261c2ac)
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 /*
22*0dc2366fSVenugopal Iyer  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate  * MAC Services Module
287c478bd9Sstevel@tonic-gate  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
327c478bd9Sstevel@tonic-gate #include <sys/stream.h>
337c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
347c478bd9Sstevel@tonic-gate #include <sys/mac.h>
357c478bd9Sstevel@tonic-gate #include <sys/mac_impl.h>
36*0dc2366fSVenugopal Iyer #include <sys/mac_client_impl.h>
37*0dc2366fSVenugopal Iyer #include <sys/mac_stat.h>
38*0dc2366fSVenugopal Iyer #include <sys/mac_soft_ring.h>
39*0dc2366fSVenugopal Iyer #include <sys/vlan.h>
407c478bd9Sstevel@tonic-gate 
41ba2e4443Sseb #define	MAC_KSTAT_NAME	"mac"
42ba2e4443Sseb #define	MAC_KSTAT_CLASS	"net"
437c478bd9Sstevel@tonic-gate 
44*0dc2366fSVenugopal Iyer enum mac_stat {
45*0dc2366fSVenugopal Iyer 	MAC_STAT_LCL,
46*0dc2366fSVenugopal Iyer 	MAC_STAT_LCLBYTES,
47*0dc2366fSVenugopal Iyer 	MAC_STAT_INTRS,
48*0dc2366fSVenugopal Iyer 	MAC_STAT_INTRBYTES,
49*0dc2366fSVenugopal Iyer 	MAC_STAT_POLLS,
50*0dc2366fSVenugopal Iyer 	MAC_STAT_POLLBYTES,
51*0dc2366fSVenugopal Iyer 	MAC_STAT_RXSDROPS,
52*0dc2366fSVenugopal Iyer 	MAC_STAT_CHU10,
53*0dc2366fSVenugopal Iyer 	MAC_STAT_CH10T50,
54*0dc2366fSVenugopal Iyer 	MAC_STAT_CHO50,
55*0dc2366fSVenugopal Iyer 	MAC_STAT_BLOCK,
56*0dc2366fSVenugopal Iyer 	MAC_STAT_UNBLOCK,
57*0dc2366fSVenugopal Iyer 	MAC_STAT_TXSDROPS,
58*0dc2366fSVenugopal Iyer 	MAC_STAT_TX_ERRORS,
59*0dc2366fSVenugopal Iyer 	MAC_STAT_MACSPOOFED,
60*0dc2366fSVenugopal Iyer 	MAC_STAT_IPSPOOFED,
61*0dc2366fSVenugopal Iyer 	MAC_STAT_DHCPSPOOFED,
62*0dc2366fSVenugopal Iyer 	MAC_STAT_RESTRICTED,
63*0dc2366fSVenugopal Iyer 	MAC_STAT_DHCPDROPPED,
64*0dc2366fSVenugopal Iyer 	MAC_STAT_MULTIRCVBYTES,
65*0dc2366fSVenugopal Iyer 	MAC_STAT_BRDCSTRCVBYTES,
66*0dc2366fSVenugopal Iyer 	MAC_STAT_MULTIXMTBYTES,
67*0dc2366fSVenugopal Iyer 	MAC_STAT_BRDCSTXMTBYTES
68*0dc2366fSVenugopal Iyer };
69*0dc2366fSVenugopal Iyer 
70ba2e4443Sseb static mac_stat_info_t	i_mac_si[] = {
71ba2e4443Sseb 	{ MAC_STAT_IFSPEED,	"ifspeed",	KSTAT_DATA_UINT64,	0 },
72ba2e4443Sseb 	{ MAC_STAT_MULTIRCV,	"multircv",	KSTAT_DATA_UINT32,	0 },
73ba2e4443Sseb 	{ MAC_STAT_BRDCSTRCV,	"brdcstrcv",	KSTAT_DATA_UINT32,	0 },
74ba2e4443Sseb 	{ MAC_STAT_MULTIXMT,	"multixmt",	KSTAT_DATA_UINT32,	0 },
75ba2e4443Sseb 	{ MAC_STAT_BRDCSTXMT,	"brdcstxmt",	KSTAT_DATA_UINT32,	0 },
76ba2e4443Sseb 	{ MAC_STAT_NORCVBUF,	"norcvbuf",	KSTAT_DATA_UINT32,	0 },
77ba2e4443Sseb 	{ MAC_STAT_IERRORS,	"ierrors",	KSTAT_DATA_UINT32,	0 },
78ba2e4443Sseb 	{ MAC_STAT_UNKNOWNS,	"unknowns",	KSTAT_DATA_UINT32,	0 },
79ba2e4443Sseb 	{ MAC_STAT_NOXMTBUF,	"noxmtbuf",	KSTAT_DATA_UINT32,	0 },
80ba2e4443Sseb 	{ MAC_STAT_OERRORS,	"oerrors",	KSTAT_DATA_UINT32,	0 },
81ba2e4443Sseb 	{ MAC_STAT_COLLISIONS,	"collisions",	KSTAT_DATA_UINT32,	0 },
829b14cf1dSgd78059 	{ MAC_STAT_UNDERFLOWS,	"uflo",		KSTAT_DATA_UINT32,	0 },
839b14cf1dSgd78059 	{ MAC_STAT_OVERFLOWS,	"oflo",		KSTAT_DATA_UINT32,	0 },
84ba2e4443Sseb 	{ MAC_STAT_RBYTES,	"rbytes",	KSTAT_DATA_UINT32,	0 },
85ba2e4443Sseb 	{ MAC_STAT_IPACKETS,	"ipackets",	KSTAT_DATA_UINT32,	0 },
86ba2e4443Sseb 	{ MAC_STAT_OBYTES,	"obytes",	KSTAT_DATA_UINT32,	0 },
87ba2e4443Sseb 	{ MAC_STAT_OPACKETS,	"opackets",	KSTAT_DATA_UINT32,	0 },
88ba2e4443Sseb 	{ MAC_STAT_RBYTES,	"rbytes64",	KSTAT_DATA_UINT64,	0 },
89ba2e4443Sseb 	{ MAC_STAT_IPACKETS,	"ipackets64",	KSTAT_DATA_UINT64,	0 },
90ba2e4443Sseb 	{ MAC_STAT_OBYTES,	"obytes64",	KSTAT_DATA_UINT64,	0 },
91ba2e4443Sseb 	{ MAC_STAT_OPACKETS,	"opackets64",	KSTAT_DATA_UINT64,	0 }
927c478bd9Sstevel@tonic-gate };
93ba2e4443Sseb #define	MAC_NKSTAT \
94ba2e4443Sseb 	(sizeof (i_mac_si) / sizeof (mac_stat_info_t))
95ba2e4443Sseb 
96ba2e4443Sseb static mac_stat_info_t	i_mac_mod_si[] = {
97ba2e4443Sseb 	{ MAC_STAT_LINK_STATE,	"link_state",	KSTAT_DATA_UINT32,
98ba2e4443Sseb 	    (uint64_t)LINK_STATE_UNKNOWN },
99ba2e4443Sseb 	{ MAC_STAT_LINK_UP,	"link_up",	KSTAT_DATA_UINT32,	0 },
100ba2e4443Sseb 	{ MAC_STAT_PROMISC,	"promisc",	KSTAT_DATA_UINT32,	0 }
101ba2e4443Sseb };
102ba2e4443Sseb #define	MAC_MOD_NKSTAT \
103ba2e4443Sseb 	(sizeof (i_mac_mod_si) / sizeof (mac_stat_info_t))
104ba2e4443Sseb 
105ba2e4443Sseb #define	MAC_MOD_KSTAT_OFFSET	0
106ba2e4443Sseb #define	MAC_KSTAT_OFFSET	MAC_MOD_KSTAT_OFFSET + MAC_MOD_NKSTAT
107ba2e4443Sseb #define	MAC_TYPE_KSTAT_OFFSET	MAC_KSTAT_OFFSET + MAC_NKSTAT
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
110*0dc2366fSVenugopal Iyer  * Definitions for per rx ring statistics
111*0dc2366fSVenugopal Iyer  */
112*0dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_rx_ring_si[] = {
113*0dc2366fSVenugopal Iyer 	{ MAC_STAT_RBYTES,	"rbytes",	KSTAT_DATA_UINT64,	0},
114*0dc2366fSVenugopal Iyer 	{ MAC_STAT_IPACKETS,	"ipackets",	KSTAT_DATA_UINT64,	0},
115*0dc2366fSVenugopal Iyer 	{ MAC_STAT_HDROPS,	"hdrops",	KSTAT_DATA_UINT64,	0}
116*0dc2366fSVenugopal Iyer };
117*0dc2366fSVenugopal Iyer #define	MAC_RX_RING_NKSTAT \
118*0dc2366fSVenugopal Iyer 	(sizeof (i_mac_rx_ring_si) / sizeof (mac_stat_info_t))
119*0dc2366fSVenugopal Iyer 
120*0dc2366fSVenugopal Iyer /*
121*0dc2366fSVenugopal Iyer  * Definitions for per tx ring statistics
122*0dc2366fSVenugopal Iyer  */
123*0dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_tx_ring_si[] = {
124*0dc2366fSVenugopal Iyer 	{ MAC_STAT_OBYTES,	"obytes",	KSTAT_DATA_UINT64,	0},
125*0dc2366fSVenugopal Iyer 	{ MAC_STAT_OPACKETS,	"opackets",	KSTAT_DATA_UINT64,	0}
126*0dc2366fSVenugopal Iyer };
127*0dc2366fSVenugopal Iyer #define	MAC_TX_RING_NKSTAT \
128*0dc2366fSVenugopal Iyer 	(sizeof (i_mac_tx_ring_si) / sizeof (mac_stat_info_t))
129*0dc2366fSVenugopal Iyer 
130*0dc2366fSVenugopal Iyer 
131*0dc2366fSVenugopal Iyer /*
132*0dc2366fSVenugopal Iyer  * Definitions for per software lane tx statistics
133*0dc2366fSVenugopal Iyer  */
134*0dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_tx_swlane_si[] = {
135*0dc2366fSVenugopal Iyer 	{ MAC_STAT_OBYTES,	"obytes",	KSTAT_DATA_UINT64,	0},
136*0dc2366fSVenugopal Iyer 	{ MAC_STAT_OPACKETS,	"opackets",	KSTAT_DATA_UINT64,	0},
137*0dc2366fSVenugopal Iyer 	{ MAC_STAT_OERRORS,	"oerrors",	KSTAT_DATA_UINT64,	0},
138*0dc2366fSVenugopal Iyer 	{ MAC_STAT_BLOCK,	"blockcnt",	KSTAT_DATA_UINT64,	0},
139*0dc2366fSVenugopal Iyer 	{ MAC_STAT_UNBLOCK,	"unblockcnt",	KSTAT_DATA_UINT64,	0},
140*0dc2366fSVenugopal Iyer 	{ MAC_STAT_TXSDROPS,	"txsdrops",	KSTAT_DATA_UINT64,	0}
141*0dc2366fSVenugopal Iyer };
142*0dc2366fSVenugopal Iyer #define	MAC_TX_SWLANE_NKSTAT \
143*0dc2366fSVenugopal Iyer 	(sizeof (i_mac_tx_swlane_si) / sizeof (mac_stat_info_t))
144*0dc2366fSVenugopal Iyer 
145*0dc2366fSVenugopal Iyer /*
146*0dc2366fSVenugopal Iyer  * Definitions for per software lane rx statistics
147*0dc2366fSVenugopal Iyer  */
148*0dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_rx_swlane_si[] = {
149*0dc2366fSVenugopal Iyer 	{ MAC_STAT_IPACKETS,	"ipackets",	KSTAT_DATA_UINT64,	0},
150*0dc2366fSVenugopal Iyer 	{ MAC_STAT_RBYTES,	"rbytes",	KSTAT_DATA_UINT64,	0},
151*0dc2366fSVenugopal Iyer 	{ MAC_STAT_LCL,		"local",	KSTAT_DATA_UINT64,	0},
152*0dc2366fSVenugopal Iyer 	{ MAC_STAT_LCLBYTES,	"localbytes",	KSTAT_DATA_UINT64,	0},
153*0dc2366fSVenugopal Iyer 	{ MAC_STAT_INTRS,	"intrs",	KSTAT_DATA_UINT64,	0},
154*0dc2366fSVenugopal Iyer 	{ MAC_STAT_INTRBYTES,	"intrbytes",	KSTAT_DATA_UINT64,	0},
155*0dc2366fSVenugopal Iyer 	{ MAC_STAT_RXSDROPS,	"rxsdrops",	KSTAT_DATA_UINT64,	0}
156*0dc2366fSVenugopal Iyer };
157*0dc2366fSVenugopal Iyer #define	MAC_RX_SWLANE_NKSTAT \
158*0dc2366fSVenugopal Iyer 	(sizeof (i_mac_rx_swlane_si) / sizeof (mac_stat_info_t))
159*0dc2366fSVenugopal Iyer 
160*0dc2366fSVenugopal Iyer /*
161*0dc2366fSVenugopal Iyer  * Definitions for per hardware lane rx statistics
162*0dc2366fSVenugopal Iyer  */
163*0dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_rx_hwlane_si[] = {
164*0dc2366fSVenugopal Iyer 	{ MAC_STAT_IPACKETS,	"ipackets",	KSTAT_DATA_UINT64,	0},
165*0dc2366fSVenugopal Iyer 	{ MAC_STAT_RBYTES,	"rbytes",	KSTAT_DATA_UINT64,	0},
166*0dc2366fSVenugopal Iyer 	{ MAC_STAT_INTRS,	"intrs",	KSTAT_DATA_UINT64,	0},
167*0dc2366fSVenugopal Iyer 	{ MAC_STAT_INTRBYTES,	"intrbytes",	KSTAT_DATA_UINT64,	0},
168*0dc2366fSVenugopal Iyer 	{ MAC_STAT_POLLS,	"polls",	KSTAT_DATA_UINT64,	0},
169*0dc2366fSVenugopal Iyer 	{ MAC_STAT_POLLBYTES,	"pollbytes",	KSTAT_DATA_UINT64,	0},
170*0dc2366fSVenugopal Iyer 	{ MAC_STAT_RXSDROPS,	"rxsdrops",	KSTAT_DATA_UINT64,	0},
171*0dc2366fSVenugopal Iyer 	{ MAC_STAT_CHU10,	"chainunder10",	KSTAT_DATA_UINT64,	0},
172*0dc2366fSVenugopal Iyer 	{ MAC_STAT_CH10T50,	"chain10to50",	KSTAT_DATA_UINT64,	0},
173*0dc2366fSVenugopal Iyer 	{ MAC_STAT_CHO50,	"chainover50",	KSTAT_DATA_UINT64,	0}
174*0dc2366fSVenugopal Iyer };
175*0dc2366fSVenugopal Iyer #define	MAC_RX_HWLANE_NKSTAT \
176*0dc2366fSVenugopal Iyer 	(sizeof (i_mac_rx_hwlane_si) / sizeof (mac_stat_info_t))
177*0dc2366fSVenugopal Iyer 
178*0dc2366fSVenugopal Iyer /*
179*0dc2366fSVenugopal Iyer  * Definitions for misc statistics
180*0dc2366fSVenugopal Iyer  */
181*0dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_misc_si[] = {
182*0dc2366fSVenugopal Iyer 	{ MAC_STAT_MULTIRCV,	"multircv",	KSTAT_DATA_UINT64,	0},
183*0dc2366fSVenugopal Iyer 	{ MAC_STAT_BRDCSTRCV,	"brdcstrcv",	KSTAT_DATA_UINT64,	0},
184*0dc2366fSVenugopal Iyer 	{ MAC_STAT_MULTIXMT,	"multixmt",	KSTAT_DATA_UINT64,	0},
185*0dc2366fSVenugopal Iyer 	{ MAC_STAT_BRDCSTXMT,	"brdcstxmt",	KSTAT_DATA_UINT64,	0},
186*0dc2366fSVenugopal Iyer 	{ MAC_STAT_MULTIRCVBYTES, "multircvbytes",   KSTAT_DATA_UINT64,	0},
187*0dc2366fSVenugopal Iyer 	{ MAC_STAT_BRDCSTRCVBYTES, "brdcstrcvbytes", KSTAT_DATA_UINT64,	0},
188*0dc2366fSVenugopal Iyer 	{ MAC_STAT_MULTIXMTBYTES,  "multixmtbytes",  KSTAT_DATA_UINT64,	0},
189*0dc2366fSVenugopal Iyer 	{ MAC_STAT_BRDCSTXMTBYTES, "brdcstxmtbytes", KSTAT_DATA_UINT64,	0},
190*0dc2366fSVenugopal Iyer 	{ MAC_STAT_TX_ERRORS,	"txerrors",	KSTAT_DATA_UINT64,	0},
191*0dc2366fSVenugopal Iyer 	{ MAC_STAT_MACSPOOFED,	"macspoofed",	KSTAT_DATA_UINT64,	0},
192*0dc2366fSVenugopal Iyer 	{ MAC_STAT_IPSPOOFED,	"ipspoofed",	KSTAT_DATA_UINT64,	0},
193*0dc2366fSVenugopal Iyer 	{ MAC_STAT_DHCPSPOOFED,	"dhcpspoofed",	KSTAT_DATA_UINT64,	0},
194*0dc2366fSVenugopal Iyer 	{ MAC_STAT_RESTRICTED,	"restricted",	KSTAT_DATA_UINT64,	0},
195*0dc2366fSVenugopal Iyer 	{ MAC_STAT_DHCPDROPPED,	"dhcpdropped",	KSTAT_DATA_UINT64,	0},
196*0dc2366fSVenugopal Iyer 	{ MAC_STAT_IPACKETS,	"ipackets",	KSTAT_DATA_UINT64,	0},
197*0dc2366fSVenugopal Iyer 	{ MAC_STAT_RBYTES,	"rbytes",	KSTAT_DATA_UINT64,	0},
198*0dc2366fSVenugopal Iyer 	{ MAC_STAT_LCL,		"local",	KSTAT_DATA_UINT64,	0},
199*0dc2366fSVenugopal Iyer 	{ MAC_STAT_LCLBYTES,	"localbytes",	KSTAT_DATA_UINT64,	0},
200*0dc2366fSVenugopal Iyer 	{ MAC_STAT_INTRS,	"intrs",	KSTAT_DATA_UINT64,	0},
201*0dc2366fSVenugopal Iyer 	{ MAC_STAT_INTRBYTES,	"intrbytes",	KSTAT_DATA_UINT64,	0},
202*0dc2366fSVenugopal Iyer 	{ MAC_STAT_POLLS,	"polls",	KSTAT_DATA_UINT64,	0},
203*0dc2366fSVenugopal Iyer 	{ MAC_STAT_POLLBYTES,	"pollbytes",	KSTAT_DATA_UINT64,	0},
204*0dc2366fSVenugopal Iyer 	{ MAC_STAT_RXSDROPS,	"rxsdrops",	KSTAT_DATA_UINT64,	0},
205*0dc2366fSVenugopal Iyer 	{ MAC_STAT_CHU10,	"chainunder10",	KSTAT_DATA_UINT64,	0},
206*0dc2366fSVenugopal Iyer 	{ MAC_STAT_CH10T50,	"chain10to50",	KSTAT_DATA_UINT64,	0},
207*0dc2366fSVenugopal Iyer 	{ MAC_STAT_CHO50,	"chainover50",	KSTAT_DATA_UINT64,	0},
208*0dc2366fSVenugopal Iyer 	{ MAC_STAT_OBYTES,	"obytes",	KSTAT_DATA_UINT64,	0},
209*0dc2366fSVenugopal Iyer 	{ MAC_STAT_OPACKETS,	"opackets",	KSTAT_DATA_UINT64,	0},
210*0dc2366fSVenugopal Iyer 	{ MAC_STAT_OERRORS,	"oerrors",	KSTAT_DATA_UINT64,	0},
211*0dc2366fSVenugopal Iyer 	{ MAC_STAT_BLOCK,	"blockcnt",	KSTAT_DATA_UINT64,	0},
212*0dc2366fSVenugopal Iyer 	{ MAC_STAT_UNBLOCK,	"unblockcnt",	KSTAT_DATA_UINT64,	0},
213*0dc2366fSVenugopal Iyer 	{ MAC_STAT_TXSDROPS,	"txsdrops",	KSTAT_DATA_UINT64,	0}
214*0dc2366fSVenugopal Iyer };
215*0dc2366fSVenugopal Iyer #define	MAC_SUMMARY_NKSTAT \
216*0dc2366fSVenugopal Iyer 	(sizeof (i_mac_misc_si) / sizeof (mac_stat_info_t))
217*0dc2366fSVenugopal Iyer 
218*0dc2366fSVenugopal Iyer /*
219*0dc2366fSVenugopal Iyer  * Definitions for per hardware lane tx statistics
220*0dc2366fSVenugopal Iyer  */
221*0dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_tx_hwlane_si[] = {
222*0dc2366fSVenugopal Iyer 	{ MAC_STAT_OBYTES,	"obytes",	KSTAT_DATA_UINT64,	0},
223*0dc2366fSVenugopal Iyer 	{ MAC_STAT_OPACKETS,	"opackets",	KSTAT_DATA_UINT64,	0},
224*0dc2366fSVenugopal Iyer 	{ MAC_STAT_OERRORS,	"oerrors",	KSTAT_DATA_UINT64,	0},
225*0dc2366fSVenugopal Iyer 	{ MAC_STAT_BLOCK,	"blockcnt",	KSTAT_DATA_UINT64,	0},
226*0dc2366fSVenugopal Iyer 	{ MAC_STAT_UNBLOCK,	"unblockcnt",	KSTAT_DATA_UINT64,	0},
227*0dc2366fSVenugopal Iyer 	{ MAC_STAT_TXSDROPS,	"txsdrops",	KSTAT_DATA_UINT64,	0}
228*0dc2366fSVenugopal Iyer };
229*0dc2366fSVenugopal Iyer #define	MAC_TX_HWLANE_NKSTAT \
230*0dc2366fSVenugopal Iyer 	(sizeof (i_mac_tx_hwlane_si) / sizeof (mac_stat_info_t))
231*0dc2366fSVenugopal Iyer 
232*0dc2366fSVenugopal Iyer /*
233*0dc2366fSVenugopal Iyer  * Definitions for per fanout rx statistics
234*0dc2366fSVenugopal Iyer  */
235*0dc2366fSVenugopal Iyer static mac_stat_info_t  i_mac_rx_fanout_si[] = {
236*0dc2366fSVenugopal Iyer 	{ MAC_STAT_RBYTES,	"rbytes",	KSTAT_DATA_UINT64,	0},
237*0dc2366fSVenugopal Iyer 	{ MAC_STAT_IPACKETS,	"ipackets",	KSTAT_DATA_UINT64,	0},
238*0dc2366fSVenugopal Iyer };
239*0dc2366fSVenugopal Iyer #define	MAC_RX_FANOUT_NKSTAT \
240*0dc2366fSVenugopal Iyer 	(sizeof (i_mac_rx_fanout_si) / sizeof (mac_stat_info_t))
241*0dc2366fSVenugopal Iyer 
242*0dc2366fSVenugopal Iyer /*
2437c478bd9Sstevel@tonic-gate  * Private functions.
2447c478bd9Sstevel@tonic-gate  */
2457c478bd9Sstevel@tonic-gate 
246*0dc2366fSVenugopal Iyer typedef struct {
247*0dc2366fSVenugopal Iyer 	uint_t	si_offset;
248*0dc2366fSVenugopal Iyer } stat_info_t;
249*0dc2366fSVenugopal Iyer 
250*0dc2366fSVenugopal Iyer #define	RX_SRS_STAT_OFF(f)	(offsetof(mac_rx_stats_t, f))
251*0dc2366fSVenugopal Iyer static stat_info_t rx_srs_stats_list[] = {
252*0dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_lclbytes)},
253*0dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_lclcnt)},
254*0dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_pollcnt)},
255*0dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_pollbytes)},
256*0dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_intrcnt)},
257*0dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_intrbytes)},
258*0dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_sdrops)},
259*0dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_chaincntundr10)},
260*0dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_chaincnt10to50)},
261*0dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_chaincntover50)},
262*0dc2366fSVenugopal Iyer 	{RX_SRS_STAT_OFF(mrs_ierrors)}
263*0dc2366fSVenugopal Iyer };
264*0dc2366fSVenugopal Iyer #define	RX_SRS_STAT_SIZE 		\
265*0dc2366fSVenugopal Iyer 	(sizeof (rx_srs_stats_list) / sizeof (stat_info_t))
266*0dc2366fSVenugopal Iyer 
267*0dc2366fSVenugopal Iyer #define	TX_SOFTRING_STAT_OFF(f)	(offsetof(mac_tx_stats_t, f))
268*0dc2366fSVenugopal Iyer static stat_info_t tx_softring_stats_list[] = {
269*0dc2366fSVenugopal Iyer 	{TX_SOFTRING_STAT_OFF(mts_obytes)},
270*0dc2366fSVenugopal Iyer 	{TX_SOFTRING_STAT_OFF(mts_opackets)},
271*0dc2366fSVenugopal Iyer 	{TX_SOFTRING_STAT_OFF(mts_oerrors)},
272*0dc2366fSVenugopal Iyer 	{TX_SOFTRING_STAT_OFF(mts_blockcnt)},
273*0dc2366fSVenugopal Iyer 	{TX_SOFTRING_STAT_OFF(mts_unblockcnt)},
274*0dc2366fSVenugopal Iyer 	{TX_SOFTRING_STAT_OFF(mts_sdrops)},
275*0dc2366fSVenugopal Iyer };
276*0dc2366fSVenugopal Iyer #define	TX_SOFTRING_STAT_SIZE 		\
277*0dc2366fSVenugopal Iyer 	(sizeof (tx_softring_stats_list) / sizeof (stat_info_t))
278*0dc2366fSVenugopal Iyer 
279*0dc2366fSVenugopal Iyer static void
280*0dc2366fSVenugopal Iyer i_mac_add_stats(void *sum, void *op1, void *op2,
281*0dc2366fSVenugopal Iyer     stat_info_t stats_list[], uint_t size)
282*0dc2366fSVenugopal Iyer {
283*0dc2366fSVenugopal Iyer 	int 	i;
284*0dc2366fSVenugopal Iyer 
285*0dc2366fSVenugopal Iyer 	for (i = 0; i < size; i++) {
286*0dc2366fSVenugopal Iyer 		uint64_t *op1_val = (uint64_t *)
287*0dc2366fSVenugopal Iyer 		    ((uchar_t *)op1 + stats_list[i].si_offset);
288*0dc2366fSVenugopal Iyer 		uint64_t *op2_val = (uint64_t *)
289*0dc2366fSVenugopal Iyer 		    ((uchar_t *)op2 + stats_list[i].si_offset);
290*0dc2366fSVenugopal Iyer 		uint64_t *sum_val = (uint64_t *)
291*0dc2366fSVenugopal Iyer 		    ((uchar_t *)sum + stats_list[i].si_offset);
292*0dc2366fSVenugopal Iyer 
293*0dc2366fSVenugopal Iyer 		*sum_val =  *op1_val + *op2_val;
294*0dc2366fSVenugopal Iyer 	}
295*0dc2366fSVenugopal Iyer }
296*0dc2366fSVenugopal Iyer 
2977c478bd9Sstevel@tonic-gate static int
298*0dc2366fSVenugopal Iyer i_mac_driver_stat_update(kstat_t *ksp, int rw)
2997c478bd9Sstevel@tonic-gate {
3007c478bd9Sstevel@tonic-gate 	mac_impl_t	*mip = ksp->ks_private;
301ba2e4443Sseb 	kstat_named_t	*knp = ksp->ks_data;
3027c478bd9Sstevel@tonic-gate 	uint_t		i;
3037c478bd9Sstevel@tonic-gate 	uint64_t	val;
304ba2e4443Sseb 	mac_stat_info_t	*msi;
305ba2e4443Sseb 	uint_t		msi_index;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	if (rw != KSTAT_READ)
3087c478bd9Sstevel@tonic-gate 		return (EACCES);
3097c478bd9Sstevel@tonic-gate 
310ba2e4443Sseb 	for (i = 0; i < mip->mi_kstat_count; i++, msi_index++) {
311ba2e4443Sseb 		if (i == MAC_MOD_KSTAT_OFFSET) {
312ba2e4443Sseb 			msi_index = 0;
313ba2e4443Sseb 			msi = i_mac_mod_si;
314ba2e4443Sseb 		} else if (i == MAC_KSTAT_OFFSET) {
315ba2e4443Sseb 			msi_index = 0;
316ba2e4443Sseb 			msi = i_mac_si;
317ba2e4443Sseb 		} else if (i == MAC_TYPE_KSTAT_OFFSET) {
318ba2e4443Sseb 			msi_index = 0;
319ba2e4443Sseb 			msi = mip->mi_type->mt_stats;
320ba2e4443Sseb 		}
3217c478bd9Sstevel@tonic-gate 
322ba2e4443Sseb 		val = mac_stat_get((mac_handle_t)mip, msi[msi_index].msi_stat);
323ba2e4443Sseb 		switch (msi[msi_index].msi_type) {
3247c478bd9Sstevel@tonic-gate 		case KSTAT_DATA_UINT64:
3257c478bd9Sstevel@tonic-gate 			knp->value.ui64 = val;
3267c478bd9Sstevel@tonic-gate 			break;
3277c478bd9Sstevel@tonic-gate 		case KSTAT_DATA_UINT32:
3287c478bd9Sstevel@tonic-gate 			knp->value.ui32 = (uint32_t)val;
3297c478bd9Sstevel@tonic-gate 			break;
3307c478bd9Sstevel@tonic-gate 		default:
3317c478bd9Sstevel@tonic-gate 			ASSERT(B_FALSE);
3327c478bd9Sstevel@tonic-gate 			break;
3337c478bd9Sstevel@tonic-gate 		}
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate 		knp++;
3367c478bd9Sstevel@tonic-gate 	}
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	return (0);
3397c478bd9Sstevel@tonic-gate }
3407c478bd9Sstevel@tonic-gate 
341ba2e4443Sseb static void
342ba2e4443Sseb i_mac_kstat_init(kstat_named_t *knp, mac_stat_info_t *si, uint_t count)
343ba2e4443Sseb {
344ba2e4443Sseb 	int i;
345ba2e4443Sseb 	for (i = 0; i < count; i++) {
346ba2e4443Sseb 		kstat_named_init(knp, si[i].msi_name, si[i].msi_type);
347ba2e4443Sseb 		knp++;
348ba2e4443Sseb 	}
349ba2e4443Sseb }
350ba2e4443Sseb 
351*0dc2366fSVenugopal Iyer static int
352*0dc2366fSVenugopal Iyer i_mac_stat_update(kstat_t *ksp, int rw, uint64_t (*fn)(void *, uint_t),
353*0dc2366fSVenugopal Iyer     mac_stat_info_t *msi, uint_t count)
354*0dc2366fSVenugopal Iyer {
355*0dc2366fSVenugopal Iyer 	kstat_named_t	*knp = ksp->ks_data;
356*0dc2366fSVenugopal Iyer 	uint_t		i;
357*0dc2366fSVenugopal Iyer 	uint64_t	val;
358*0dc2366fSVenugopal Iyer 
359*0dc2366fSVenugopal Iyer 	if (rw != KSTAT_READ)
360*0dc2366fSVenugopal Iyer 		return (EACCES);
361*0dc2366fSVenugopal Iyer 
362*0dc2366fSVenugopal Iyer 	for (i = 0; i < count; i++) {
363*0dc2366fSVenugopal Iyer 		val = fn(ksp->ks_private, msi[i].msi_stat);
364*0dc2366fSVenugopal Iyer 
365*0dc2366fSVenugopal Iyer 		switch (msi[i].msi_type) {
366*0dc2366fSVenugopal Iyer 		case KSTAT_DATA_UINT64:
367*0dc2366fSVenugopal Iyer 			knp->value.ui64 = val;
368*0dc2366fSVenugopal Iyer 			break;
369*0dc2366fSVenugopal Iyer 		case KSTAT_DATA_UINT32:
370*0dc2366fSVenugopal Iyer 			knp->value.ui32 = (uint32_t)val;
371*0dc2366fSVenugopal Iyer 			break;
372*0dc2366fSVenugopal Iyer 		default:
373*0dc2366fSVenugopal Iyer 			ASSERT(B_FALSE);
374*0dc2366fSVenugopal Iyer 			break;
375*0dc2366fSVenugopal Iyer 		}
376*0dc2366fSVenugopal Iyer 		knp++;
377*0dc2366fSVenugopal Iyer 	}
378*0dc2366fSVenugopal Iyer 	return (0);
379*0dc2366fSVenugopal Iyer }
380*0dc2366fSVenugopal Iyer 
381*0dc2366fSVenugopal Iyer /*
382*0dc2366fSVenugopal Iyer  * Create kstat with given name - statname, update function - fn
383*0dc2366fSVenugopal Iyer  * and initialize it with given names - init_stat_info
384*0dc2366fSVenugopal Iyer  */
385*0dc2366fSVenugopal Iyer static kstat_t *
386*0dc2366fSVenugopal Iyer i_mac_stat_create(void *handle, const char *modname, const char *statname,
387*0dc2366fSVenugopal Iyer     int (*fn) (kstat_t *, int),
388*0dc2366fSVenugopal Iyer     mac_stat_info_t *init_stat_info, uint_t count)
389*0dc2366fSVenugopal Iyer {
390*0dc2366fSVenugopal Iyer 	kstat_t		*ksp;
391*0dc2366fSVenugopal Iyer 	kstat_named_t	*knp;
392*0dc2366fSVenugopal Iyer 
393*0dc2366fSVenugopal Iyer 	ksp = kstat_create(modname, 0, statname, "net",
394*0dc2366fSVenugopal Iyer 	    KSTAT_TYPE_NAMED, count, 0);
395*0dc2366fSVenugopal Iyer 
396*0dc2366fSVenugopal Iyer 	if (ksp == NULL)
397*0dc2366fSVenugopal Iyer 		return (NULL);
398*0dc2366fSVenugopal Iyer 
399*0dc2366fSVenugopal Iyer 	ksp->ks_update = fn;
400*0dc2366fSVenugopal Iyer 	ksp->ks_private = handle;
401*0dc2366fSVenugopal Iyer 
402*0dc2366fSVenugopal Iyer 	knp = (kstat_named_t *)ksp->ks_data;
403*0dc2366fSVenugopal Iyer 	i_mac_kstat_init(knp, init_stat_info, count);
404*0dc2366fSVenugopal Iyer 	kstat_install(ksp);
405*0dc2366fSVenugopal Iyer 
406*0dc2366fSVenugopal Iyer 	return (ksp);
407*0dc2366fSVenugopal Iyer }
408*0dc2366fSVenugopal Iyer 
409*0dc2366fSVenugopal Iyer /*
410*0dc2366fSVenugopal Iyer  * Per rx ring statistics
411*0dc2366fSVenugopal Iyer  */
412*0dc2366fSVenugopal Iyer uint64_t
413*0dc2366fSVenugopal Iyer mac_rx_ring_stat_get(void *handle, uint_t stat)
414*0dc2366fSVenugopal Iyer {
415*0dc2366fSVenugopal Iyer 	mac_ring_t		*ring = (mac_ring_t *)handle;
416*0dc2366fSVenugopal Iyer 	uint64_t		val = 0;
417*0dc2366fSVenugopal Iyer 
418*0dc2366fSVenugopal Iyer 	/*
419*0dc2366fSVenugopal Iyer 	 * XXX Every ring-capable driver must implement an entry point to
420*0dc2366fSVenugopal Iyer 	 * query per ring statistics. CR 6893122 tracks this work item.
421*0dc2366fSVenugopal Iyer 	 * Once this bug is fixed, the framework should fail registration
422*0dc2366fSVenugopal Iyer 	 * for a driver that does not implement this entry point and
423*0dc2366fSVenugopal Iyer 	 * assert ring->mr_stat != NULL here.
424*0dc2366fSVenugopal Iyer 	 */
425*0dc2366fSVenugopal Iyer 	if (ring->mr_stat != NULL)
426*0dc2366fSVenugopal Iyer 		ring->mr_stat(ring->mr_driver, stat, &val);
427*0dc2366fSVenugopal Iyer 
428*0dc2366fSVenugopal Iyer 	return (val);
429*0dc2366fSVenugopal Iyer }
430*0dc2366fSVenugopal Iyer 
431*0dc2366fSVenugopal Iyer static int
432*0dc2366fSVenugopal Iyer i_mac_rx_ring_stat_update(kstat_t *ksp, int rw)
433*0dc2366fSVenugopal Iyer {
434*0dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, mac_rx_ring_stat_get,
435*0dc2366fSVenugopal Iyer 	    i_mac_rx_ring_si, MAC_RX_RING_NKSTAT));
436*0dc2366fSVenugopal Iyer }
437*0dc2366fSVenugopal Iyer 
438*0dc2366fSVenugopal Iyer static void
439*0dc2366fSVenugopal Iyer i_mac_rx_ring_stat_create(mac_ring_t *ring, const char *modname,
440*0dc2366fSVenugopal Iyer     const char *statname)
441*0dc2366fSVenugopal Iyer {
442*0dc2366fSVenugopal Iyer 	kstat_t		*ksp;
443*0dc2366fSVenugopal Iyer 
444*0dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(ring, modname, statname,
445*0dc2366fSVenugopal Iyer 	    i_mac_rx_ring_stat_update, i_mac_rx_ring_si, MAC_RX_RING_NKSTAT);
446*0dc2366fSVenugopal Iyer 
447*0dc2366fSVenugopal Iyer 	ring->mr_ksp = ksp;
448*0dc2366fSVenugopal Iyer }
449*0dc2366fSVenugopal Iyer 
450*0dc2366fSVenugopal Iyer /*
451*0dc2366fSVenugopal Iyer  * Per tx ring statistics
452*0dc2366fSVenugopal Iyer  */
453*0dc2366fSVenugopal Iyer uint64_t
454*0dc2366fSVenugopal Iyer mac_tx_ring_stat_get(void *handle, uint_t stat)
455*0dc2366fSVenugopal Iyer {
456*0dc2366fSVenugopal Iyer 	mac_ring_t		*ring = (mac_ring_t *)handle;
457*0dc2366fSVenugopal Iyer 	uint64_t		val = 0;
458*0dc2366fSVenugopal Iyer 
459*0dc2366fSVenugopal Iyer 	/*
460*0dc2366fSVenugopal Iyer 	 * XXX Every ring-capable driver must implement an entry point to
461*0dc2366fSVenugopal Iyer 	 * query per ring statistics. CR 6893122 tracks this work item.
462*0dc2366fSVenugopal Iyer 	 * Once this bug is fixed, the framework should fail registration
463*0dc2366fSVenugopal Iyer 	 * for a driver that does not implement this entry point and
464*0dc2366fSVenugopal Iyer 	 * assert ring->mr_stat != NULL here.
465*0dc2366fSVenugopal Iyer 	 */
466*0dc2366fSVenugopal Iyer 	if (ring->mr_stat != NULL)
467*0dc2366fSVenugopal Iyer 		ring->mr_stat(ring->mr_driver, stat, &val);
468*0dc2366fSVenugopal Iyer 
469*0dc2366fSVenugopal Iyer 	return (val);
470*0dc2366fSVenugopal Iyer }
471*0dc2366fSVenugopal Iyer 
472*0dc2366fSVenugopal Iyer static int
473*0dc2366fSVenugopal Iyer i_mac_tx_ring_stat_update(kstat_t *ksp, int rw)
474*0dc2366fSVenugopal Iyer {
475*0dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, mac_tx_ring_stat_get,
476*0dc2366fSVenugopal Iyer 	    i_mac_tx_ring_si, MAC_TX_RING_NKSTAT));
477*0dc2366fSVenugopal Iyer }
478*0dc2366fSVenugopal Iyer 
479*0dc2366fSVenugopal Iyer static void
480*0dc2366fSVenugopal Iyer i_mac_tx_ring_stat_create(mac_ring_t *ring, const char *modname,
481*0dc2366fSVenugopal Iyer     const char *statname)
482*0dc2366fSVenugopal Iyer {
483*0dc2366fSVenugopal Iyer 	kstat_t		*ksp;
484*0dc2366fSVenugopal Iyer 
485*0dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(ring, modname, statname,
486*0dc2366fSVenugopal Iyer 	    i_mac_tx_ring_stat_update, i_mac_tx_ring_si, MAC_TX_RING_NKSTAT);
487*0dc2366fSVenugopal Iyer 
488*0dc2366fSVenugopal Iyer 	ring->mr_ksp = ksp;
489*0dc2366fSVenugopal Iyer }
490*0dc2366fSVenugopal Iyer 
491*0dc2366fSVenugopal Iyer /*
492*0dc2366fSVenugopal Iyer  * Per software lane tx statistics
493*0dc2366fSVenugopal Iyer  */
494*0dc2366fSVenugopal Iyer static uint64_t
495*0dc2366fSVenugopal Iyer i_mac_tx_swlane_stat_get(void *handle, uint_t stat)
496*0dc2366fSVenugopal Iyer {
497*0dc2366fSVenugopal Iyer 	mac_soft_ring_set_t *mac_srs = (mac_soft_ring_set_t *)handle;
498*0dc2366fSVenugopal Iyer 	mac_tx_stats_t *mac_tx_stat = &mac_srs->srs_tx.st_stat;
499*0dc2366fSVenugopal Iyer 
500*0dc2366fSVenugopal Iyer 	switch (stat) {
501*0dc2366fSVenugopal Iyer 	case MAC_STAT_OBYTES:
502*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_obytes);
503*0dc2366fSVenugopal Iyer 
504*0dc2366fSVenugopal Iyer 	case MAC_STAT_OPACKETS:
505*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_opackets);
506*0dc2366fSVenugopal Iyer 
507*0dc2366fSVenugopal Iyer 	case MAC_STAT_OERRORS:
508*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_oerrors);
509*0dc2366fSVenugopal Iyer 
510*0dc2366fSVenugopal Iyer 	case MAC_STAT_BLOCK:
511*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_blockcnt);
512*0dc2366fSVenugopal Iyer 
513*0dc2366fSVenugopal Iyer 	case MAC_STAT_UNBLOCK:
514*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_unblockcnt);
515*0dc2366fSVenugopal Iyer 
516*0dc2366fSVenugopal Iyer 	case MAC_STAT_TXSDROPS:
517*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_sdrops);
518*0dc2366fSVenugopal Iyer 
519*0dc2366fSVenugopal Iyer 	default:
520*0dc2366fSVenugopal Iyer 		return (0);
521*0dc2366fSVenugopal Iyer 	}
522*0dc2366fSVenugopal Iyer }
523*0dc2366fSVenugopal Iyer 
524*0dc2366fSVenugopal Iyer static int
525*0dc2366fSVenugopal Iyer i_mac_tx_swlane_stat_update(kstat_t *ksp, int rw)
526*0dc2366fSVenugopal Iyer {
527*0dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, i_mac_tx_swlane_stat_get,
528*0dc2366fSVenugopal Iyer 	    i_mac_tx_swlane_si, MAC_TX_SWLANE_NKSTAT));
529*0dc2366fSVenugopal Iyer }
530*0dc2366fSVenugopal Iyer 
531*0dc2366fSVenugopal Iyer static void
532*0dc2366fSVenugopal Iyer i_mac_tx_swlane_stat_create(mac_soft_ring_set_t *mac_srs, const char *modname,
533*0dc2366fSVenugopal Iyer     const char *statname)
534*0dc2366fSVenugopal Iyer {
535*0dc2366fSVenugopal Iyer 	kstat_t		*ksp;
536*0dc2366fSVenugopal Iyer 
537*0dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(mac_srs, modname, statname,
538*0dc2366fSVenugopal Iyer 	    i_mac_tx_swlane_stat_update, i_mac_tx_swlane_si,
539*0dc2366fSVenugopal Iyer 	    MAC_TX_SWLANE_NKSTAT);
540*0dc2366fSVenugopal Iyer 
541*0dc2366fSVenugopal Iyer 	mac_srs->srs_ksp = ksp;
542*0dc2366fSVenugopal Iyer }
543*0dc2366fSVenugopal Iyer 
544*0dc2366fSVenugopal Iyer /*
545*0dc2366fSVenugopal Iyer  * Per software lane rx statistics
546*0dc2366fSVenugopal Iyer  */
547*0dc2366fSVenugopal Iyer static uint64_t
548*0dc2366fSVenugopal Iyer i_mac_rx_swlane_stat_get(void *handle, uint_t stat)
549*0dc2366fSVenugopal Iyer {
550*0dc2366fSVenugopal Iyer 	mac_soft_ring_set_t	*mac_srs = (mac_soft_ring_set_t *)handle;
551*0dc2366fSVenugopal Iyer 	mac_rx_stats_t		*mac_rx_stat = &mac_srs->srs_rx.sr_stat;
552*0dc2366fSVenugopal Iyer 
553*0dc2366fSVenugopal Iyer 	switch (stat) {
554*0dc2366fSVenugopal Iyer 	case MAC_STAT_IPACKETS:
555*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrcnt +
556*0dc2366fSVenugopal Iyer 		    mac_rx_stat->mrs_lclcnt);
557*0dc2366fSVenugopal Iyer 
558*0dc2366fSVenugopal Iyer 	case MAC_STAT_RBYTES:
559*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrbytes +
560*0dc2366fSVenugopal Iyer 		    mac_rx_stat->mrs_lclbytes);
561*0dc2366fSVenugopal Iyer 
562*0dc2366fSVenugopal Iyer 	case MAC_STAT_LCL:
563*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_lclcnt);
564*0dc2366fSVenugopal Iyer 
565*0dc2366fSVenugopal Iyer 	case MAC_STAT_LCLBYTES:
566*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_lclbytes);
567*0dc2366fSVenugopal Iyer 
568*0dc2366fSVenugopal Iyer 	case MAC_STAT_INTRS:
569*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrcnt);
570*0dc2366fSVenugopal Iyer 
571*0dc2366fSVenugopal Iyer 	case MAC_STAT_INTRBYTES:
572*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrbytes);
573*0dc2366fSVenugopal Iyer 
574*0dc2366fSVenugopal Iyer 	case MAC_STAT_RXSDROPS:
575*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_sdrops);
576*0dc2366fSVenugopal Iyer 
577*0dc2366fSVenugopal Iyer 	default:
578*0dc2366fSVenugopal Iyer 		return (0);
579*0dc2366fSVenugopal Iyer 	}
580*0dc2366fSVenugopal Iyer }
581*0dc2366fSVenugopal Iyer 
582*0dc2366fSVenugopal Iyer static int
583*0dc2366fSVenugopal Iyer i_mac_rx_swlane_stat_update(kstat_t *ksp, int rw)
584*0dc2366fSVenugopal Iyer {
585*0dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, i_mac_rx_swlane_stat_get,
586*0dc2366fSVenugopal Iyer 	    i_mac_rx_swlane_si, MAC_RX_SWLANE_NKSTAT));
587*0dc2366fSVenugopal Iyer }
588*0dc2366fSVenugopal Iyer 
589*0dc2366fSVenugopal Iyer static void
590*0dc2366fSVenugopal Iyer i_mac_rx_swlane_stat_create(mac_soft_ring_set_t *mac_srs, const char *modname,
591*0dc2366fSVenugopal Iyer     const char *statname)
592*0dc2366fSVenugopal Iyer {
593*0dc2366fSVenugopal Iyer 	kstat_t		*ksp;
594*0dc2366fSVenugopal Iyer 
595*0dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(mac_srs, modname, statname,
596*0dc2366fSVenugopal Iyer 	    i_mac_rx_swlane_stat_update, i_mac_rx_swlane_si,
597*0dc2366fSVenugopal Iyer 	    MAC_RX_SWLANE_NKSTAT);
598*0dc2366fSVenugopal Iyer 
599*0dc2366fSVenugopal Iyer 	mac_srs->srs_ksp = ksp;
600*0dc2366fSVenugopal Iyer }
601*0dc2366fSVenugopal Iyer 
602*0dc2366fSVenugopal Iyer 
603*0dc2366fSVenugopal Iyer /*
604*0dc2366fSVenugopal Iyer  * Per hardware lane rx statistics
605*0dc2366fSVenugopal Iyer  */
606*0dc2366fSVenugopal Iyer static uint64_t
607*0dc2366fSVenugopal Iyer i_mac_rx_hwlane_stat_get(void *handle, uint_t stat)
608*0dc2366fSVenugopal Iyer {
609*0dc2366fSVenugopal Iyer 	mac_soft_ring_set_t	*mac_srs = (mac_soft_ring_set_t *)handle;
610*0dc2366fSVenugopal Iyer 	mac_rx_stats_t		*mac_rx_stat = &mac_srs->srs_rx.sr_stat;
611*0dc2366fSVenugopal Iyer 
612*0dc2366fSVenugopal Iyer 	switch (stat) {
613*0dc2366fSVenugopal Iyer 	case MAC_STAT_IPACKETS:
614*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrcnt +
615*0dc2366fSVenugopal Iyer 		    mac_rx_stat->mrs_pollcnt);
616*0dc2366fSVenugopal Iyer 
617*0dc2366fSVenugopal Iyer 	case MAC_STAT_RBYTES:
618*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrbytes +
619*0dc2366fSVenugopal Iyer 		    mac_rx_stat->mrs_pollbytes);
620*0dc2366fSVenugopal Iyer 
621*0dc2366fSVenugopal Iyer 	case MAC_STAT_INTRS:
622*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrcnt);
623*0dc2366fSVenugopal Iyer 
624*0dc2366fSVenugopal Iyer 	case MAC_STAT_INTRBYTES:
625*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrbytes);
626*0dc2366fSVenugopal Iyer 
627*0dc2366fSVenugopal Iyer 	case MAC_STAT_POLLS:
628*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_pollcnt);
629*0dc2366fSVenugopal Iyer 
630*0dc2366fSVenugopal Iyer 	case MAC_STAT_POLLBYTES:
631*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_pollbytes);
632*0dc2366fSVenugopal Iyer 
633*0dc2366fSVenugopal Iyer 	case MAC_STAT_RXSDROPS:
634*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_sdrops);
635*0dc2366fSVenugopal Iyer 
636*0dc2366fSVenugopal Iyer 	case MAC_STAT_CHU10:
637*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_chaincntundr10);
638*0dc2366fSVenugopal Iyer 
639*0dc2366fSVenugopal Iyer 	case MAC_STAT_CH10T50:
640*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_chaincnt10to50);
641*0dc2366fSVenugopal Iyer 
642*0dc2366fSVenugopal Iyer 	case MAC_STAT_CHO50:
643*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_chaincntover50);
644*0dc2366fSVenugopal Iyer 
645*0dc2366fSVenugopal Iyer 	default:
646*0dc2366fSVenugopal Iyer 		return (0);
647*0dc2366fSVenugopal Iyer 	}
648*0dc2366fSVenugopal Iyer }
649*0dc2366fSVenugopal Iyer 
650*0dc2366fSVenugopal Iyer static int
651*0dc2366fSVenugopal Iyer i_mac_rx_hwlane_stat_update(kstat_t *ksp, int rw)
652*0dc2366fSVenugopal Iyer {
653*0dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, i_mac_rx_hwlane_stat_get,
654*0dc2366fSVenugopal Iyer 	    i_mac_rx_hwlane_si, MAC_RX_HWLANE_NKSTAT));
655*0dc2366fSVenugopal Iyer }
656*0dc2366fSVenugopal Iyer 
657*0dc2366fSVenugopal Iyer static void
658*0dc2366fSVenugopal Iyer i_mac_rx_hwlane_stat_create(mac_soft_ring_set_t *mac_srs, const char *modname,
659*0dc2366fSVenugopal Iyer     const char *statname)
660*0dc2366fSVenugopal Iyer {
661*0dc2366fSVenugopal Iyer 	kstat_t		*ksp;
662*0dc2366fSVenugopal Iyer 
663*0dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(mac_srs, modname, statname,
664*0dc2366fSVenugopal Iyer 	    i_mac_rx_hwlane_stat_update, i_mac_rx_hwlane_si,
665*0dc2366fSVenugopal Iyer 	    MAC_RX_HWLANE_NKSTAT);
666*0dc2366fSVenugopal Iyer 
667*0dc2366fSVenugopal Iyer 	mac_srs->srs_ksp = ksp;
668*0dc2366fSVenugopal Iyer }
669*0dc2366fSVenugopal Iyer 
670*0dc2366fSVenugopal Iyer 
671*0dc2366fSVenugopal Iyer /*
672*0dc2366fSVenugopal Iyer  * Misc statistics
673*0dc2366fSVenugopal Iyer  *
674*0dc2366fSVenugopal Iyer  * Counts for
675*0dc2366fSVenugopal Iyer  *	- Multicast/broadcast Rx/Tx counts
676*0dc2366fSVenugopal Iyer  *	- Tx errors
677*0dc2366fSVenugopal Iyer  */
678*0dc2366fSVenugopal Iyer static uint64_t
679*0dc2366fSVenugopal Iyer i_mac_misc_stat_get(void *handle, uint_t stat)
680*0dc2366fSVenugopal Iyer {
681*0dc2366fSVenugopal Iyer 	flow_entry_t 		*flent = handle;
682*0dc2366fSVenugopal Iyer 	mac_client_impl_t 	*mcip = flent->fe_mcip;
683*0dc2366fSVenugopal Iyer 	mac_misc_stats_t	*mac_misc_stat = &mcip->mci_misc_stat;
684*0dc2366fSVenugopal Iyer 	mac_rx_stats_t		*mac_rx_stat;
685*0dc2366fSVenugopal Iyer 	mac_tx_stats_t		*mac_tx_stat;
686*0dc2366fSVenugopal Iyer 
687*0dc2366fSVenugopal Iyer 	mac_rx_stat = &mac_misc_stat->mms_defunctrxlanestats;
688*0dc2366fSVenugopal Iyer 	mac_tx_stat = &mac_misc_stat->mms_defuncttxlanestats;
689*0dc2366fSVenugopal Iyer 
690*0dc2366fSVenugopal Iyer 	switch (stat) {
691*0dc2366fSVenugopal Iyer 	case MAC_STAT_MULTIRCV:
692*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_multircv);
693*0dc2366fSVenugopal Iyer 
694*0dc2366fSVenugopal Iyer 	case MAC_STAT_BRDCSTRCV:
695*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_brdcstrcv);
696*0dc2366fSVenugopal Iyer 
697*0dc2366fSVenugopal Iyer 	case MAC_STAT_MULTIXMT:
698*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_multixmt);
699*0dc2366fSVenugopal Iyer 
700*0dc2366fSVenugopal Iyer 	case MAC_STAT_BRDCSTXMT:
701*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_brdcstxmt);
702*0dc2366fSVenugopal Iyer 
703*0dc2366fSVenugopal Iyer 	case MAC_STAT_MULTIRCVBYTES:
704*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_multircvbytes);
705*0dc2366fSVenugopal Iyer 
706*0dc2366fSVenugopal Iyer 	case MAC_STAT_BRDCSTRCVBYTES:
707*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_brdcstrcvbytes);
708*0dc2366fSVenugopal Iyer 
709*0dc2366fSVenugopal Iyer 	case MAC_STAT_MULTIXMTBYTES:
710*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_multixmtbytes);
711*0dc2366fSVenugopal Iyer 
712*0dc2366fSVenugopal Iyer 	case MAC_STAT_BRDCSTXMTBYTES:
713*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_brdcstxmtbytes);
714*0dc2366fSVenugopal Iyer 
715*0dc2366fSVenugopal Iyer 	case MAC_STAT_TX_ERRORS:
716*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_txerrors);
717*0dc2366fSVenugopal Iyer 
718*0dc2366fSVenugopal Iyer 	case MAC_STAT_MACSPOOFED:
719*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_macspoofed);
720*0dc2366fSVenugopal Iyer 
721*0dc2366fSVenugopal Iyer 	case MAC_STAT_IPSPOOFED:
722*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_ipspoofed);
723*0dc2366fSVenugopal Iyer 
724*0dc2366fSVenugopal Iyer 	case MAC_STAT_DHCPSPOOFED:
725*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_dhcpspoofed);
726*0dc2366fSVenugopal Iyer 
727*0dc2366fSVenugopal Iyer 	case MAC_STAT_RESTRICTED:
728*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_restricted);
729*0dc2366fSVenugopal Iyer 
730*0dc2366fSVenugopal Iyer 	case MAC_STAT_DHCPDROPPED:
731*0dc2366fSVenugopal Iyer 		return (mac_misc_stat->mms_dhcpdropped);
732*0dc2366fSVenugopal Iyer 
733*0dc2366fSVenugopal Iyer 	case MAC_STAT_IPACKETS:
734*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrcnt +
735*0dc2366fSVenugopal Iyer 		    mac_rx_stat->mrs_pollcnt);
736*0dc2366fSVenugopal Iyer 
737*0dc2366fSVenugopal Iyer 	case MAC_STAT_RBYTES:
738*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrbytes +
739*0dc2366fSVenugopal Iyer 		    mac_rx_stat->mrs_pollbytes);
740*0dc2366fSVenugopal Iyer 
741*0dc2366fSVenugopal Iyer 	case MAC_STAT_LCL:
742*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_lclcnt);
743*0dc2366fSVenugopal Iyer 
744*0dc2366fSVenugopal Iyer 	case MAC_STAT_LCLBYTES:
745*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_lclbytes);
746*0dc2366fSVenugopal Iyer 
747*0dc2366fSVenugopal Iyer 	case MAC_STAT_INTRS:
748*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrcnt);
749*0dc2366fSVenugopal Iyer 
750*0dc2366fSVenugopal Iyer 	case MAC_STAT_INTRBYTES:
751*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_intrbytes);
752*0dc2366fSVenugopal Iyer 
753*0dc2366fSVenugopal Iyer 	case MAC_STAT_POLLS:
754*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_pollcnt);
755*0dc2366fSVenugopal Iyer 
756*0dc2366fSVenugopal Iyer 	case MAC_STAT_POLLBYTES:
757*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_pollbytes);
758*0dc2366fSVenugopal Iyer 
759*0dc2366fSVenugopal Iyer 	case MAC_STAT_RXSDROPS:
760*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_sdrops);
761*0dc2366fSVenugopal Iyer 
762*0dc2366fSVenugopal Iyer 	case MAC_STAT_CHU10:
763*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_chaincntundr10);
764*0dc2366fSVenugopal Iyer 
765*0dc2366fSVenugopal Iyer 	case MAC_STAT_CH10T50:
766*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_chaincnt10to50);
767*0dc2366fSVenugopal Iyer 
768*0dc2366fSVenugopal Iyer 	case MAC_STAT_CHO50:
769*0dc2366fSVenugopal Iyer 		return (mac_rx_stat->mrs_chaincntover50);
770*0dc2366fSVenugopal Iyer 
771*0dc2366fSVenugopal Iyer 	case MAC_STAT_OBYTES:
772*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_obytes);
773*0dc2366fSVenugopal Iyer 
774*0dc2366fSVenugopal Iyer 	case MAC_STAT_OPACKETS:
775*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_opackets);
776*0dc2366fSVenugopal Iyer 
777*0dc2366fSVenugopal Iyer 	case MAC_STAT_OERRORS:
778*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_oerrors);
779*0dc2366fSVenugopal Iyer 
780*0dc2366fSVenugopal Iyer 	case MAC_STAT_BLOCK:
781*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_blockcnt);
782*0dc2366fSVenugopal Iyer 
783*0dc2366fSVenugopal Iyer 	case MAC_STAT_UNBLOCK:
784*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_unblockcnt);
785*0dc2366fSVenugopal Iyer 
786*0dc2366fSVenugopal Iyer 	case MAC_STAT_TXSDROPS:
787*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_sdrops);
788*0dc2366fSVenugopal Iyer 
789*0dc2366fSVenugopal Iyer 	default:
790*0dc2366fSVenugopal Iyer 		return (0);
791*0dc2366fSVenugopal Iyer 	}
792*0dc2366fSVenugopal Iyer }
793*0dc2366fSVenugopal Iyer 
794*0dc2366fSVenugopal Iyer static int
795*0dc2366fSVenugopal Iyer i_mac_misc_stat_update(kstat_t *ksp, int rw)
796*0dc2366fSVenugopal Iyer {
797*0dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, i_mac_misc_stat_get,
798*0dc2366fSVenugopal Iyer 	    i_mac_misc_si, MAC_SUMMARY_NKSTAT));
799*0dc2366fSVenugopal Iyer }
800*0dc2366fSVenugopal Iyer 
801*0dc2366fSVenugopal Iyer static void
802*0dc2366fSVenugopal Iyer i_mac_misc_stat_create(flow_entry_t *flent, const char *modname,
803*0dc2366fSVenugopal Iyer     const char *statname)
804*0dc2366fSVenugopal Iyer {
805*0dc2366fSVenugopal Iyer 	kstat_t		*ksp;
806*0dc2366fSVenugopal Iyer 
807*0dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(flent, modname, statname,
808*0dc2366fSVenugopal Iyer 	    i_mac_misc_stat_update, i_mac_misc_si,
809*0dc2366fSVenugopal Iyer 	    MAC_SUMMARY_NKSTAT);
810*0dc2366fSVenugopal Iyer 
811*0dc2366fSVenugopal Iyer 	flent->fe_misc_stat_ksp = ksp;
812*0dc2366fSVenugopal Iyer }
813*0dc2366fSVenugopal Iyer 
814*0dc2366fSVenugopal Iyer /*
815*0dc2366fSVenugopal Iyer  * Per hardware lane tx statistics
816*0dc2366fSVenugopal Iyer  */
817*0dc2366fSVenugopal Iyer static uint64_t
818*0dc2366fSVenugopal Iyer i_mac_tx_hwlane_stat_get(void *handle, uint_t stat)
819*0dc2366fSVenugopal Iyer {
820*0dc2366fSVenugopal Iyer 	mac_soft_ring_t	*ringp = (mac_soft_ring_t *)handle;
821*0dc2366fSVenugopal Iyer 	mac_tx_stats_t	*mac_tx_stat = &ringp->s_st_stat;
822*0dc2366fSVenugopal Iyer 
823*0dc2366fSVenugopal Iyer 	switch (stat) {
824*0dc2366fSVenugopal Iyer 	case MAC_STAT_OBYTES:
825*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_obytes);
826*0dc2366fSVenugopal Iyer 
827*0dc2366fSVenugopal Iyer 	case MAC_STAT_OPACKETS:
828*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_opackets);
829*0dc2366fSVenugopal Iyer 
830*0dc2366fSVenugopal Iyer 	case MAC_STAT_OERRORS:
831*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_oerrors);
832*0dc2366fSVenugopal Iyer 
833*0dc2366fSVenugopal Iyer 	case MAC_STAT_BLOCK:
834*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_blockcnt);
835*0dc2366fSVenugopal Iyer 
836*0dc2366fSVenugopal Iyer 	case MAC_STAT_UNBLOCK:
837*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_unblockcnt);
838*0dc2366fSVenugopal Iyer 
839*0dc2366fSVenugopal Iyer 	case MAC_STAT_TXSDROPS:
840*0dc2366fSVenugopal Iyer 		return (mac_tx_stat->mts_sdrops);
841*0dc2366fSVenugopal Iyer 
842*0dc2366fSVenugopal Iyer 	default:
843*0dc2366fSVenugopal Iyer 		return (0);
844*0dc2366fSVenugopal Iyer 	}
845*0dc2366fSVenugopal Iyer }
846*0dc2366fSVenugopal Iyer 
847*0dc2366fSVenugopal Iyer static int
848*0dc2366fSVenugopal Iyer i_mac_tx_hwlane_stat_update(kstat_t *ksp, int rw)
849*0dc2366fSVenugopal Iyer {
850*0dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, i_mac_tx_hwlane_stat_get,
851*0dc2366fSVenugopal Iyer 	    i_mac_tx_hwlane_si, MAC_TX_HWLANE_NKSTAT));
852*0dc2366fSVenugopal Iyer }
853*0dc2366fSVenugopal Iyer 
854*0dc2366fSVenugopal Iyer static void
855*0dc2366fSVenugopal Iyer i_mac_tx_hwlane_stat_create(mac_soft_ring_t *ringp, const char *modname,
856*0dc2366fSVenugopal Iyer     const char *statname)
857*0dc2366fSVenugopal Iyer {
858*0dc2366fSVenugopal Iyer 	kstat_t		*ksp;
859*0dc2366fSVenugopal Iyer 
860*0dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(ringp, modname, statname,
861*0dc2366fSVenugopal Iyer 	    i_mac_tx_hwlane_stat_update, i_mac_tx_hwlane_si,
862*0dc2366fSVenugopal Iyer 	    MAC_TX_HWLANE_NKSTAT);
863*0dc2366fSVenugopal Iyer 
864*0dc2366fSVenugopal Iyer 	ringp->s_ring_ksp = ksp;
865*0dc2366fSVenugopal Iyer }
866*0dc2366fSVenugopal Iyer 
867*0dc2366fSVenugopal Iyer /*
868*0dc2366fSVenugopal Iyer  * Per fanout rx statistics
869*0dc2366fSVenugopal Iyer  */
870*0dc2366fSVenugopal Iyer static uint64_t
871*0dc2366fSVenugopal Iyer i_mac_rx_fanout_stat_get(void *handle, uint_t stat)
872*0dc2366fSVenugopal Iyer {
873*0dc2366fSVenugopal Iyer 	mac_soft_ring_t 	*tcp_ringp = (mac_soft_ring_t *)handle;
874*0dc2366fSVenugopal Iyer 	mac_soft_ring_t		*udp_ringp = NULL, *oth_ringp = NULL;
875*0dc2366fSVenugopal Iyer 	mac_soft_ring_set_t 	*mac_srs = tcp_ringp->s_ring_set;
876*0dc2366fSVenugopal Iyer 	int			index;
877*0dc2366fSVenugopal Iyer 	uint64_t		val;
878*0dc2366fSVenugopal Iyer 
879*0dc2366fSVenugopal Iyer 	mutex_enter(&mac_srs->srs_lock);
880*0dc2366fSVenugopal Iyer 	/* Extract corresponding udp and oth ring pointers */
881*0dc2366fSVenugopal Iyer 	for (index = 0; mac_srs->srs_tcp_soft_rings[index] != NULL; index++) {
882*0dc2366fSVenugopal Iyer 		if (mac_srs->srs_tcp_soft_rings[index] == tcp_ringp) {
883*0dc2366fSVenugopal Iyer 			udp_ringp = mac_srs->srs_udp_soft_rings[index];
884*0dc2366fSVenugopal Iyer 			oth_ringp = mac_srs->srs_oth_soft_rings[index];
885*0dc2366fSVenugopal Iyer 			break;
886*0dc2366fSVenugopal Iyer 		}
887*0dc2366fSVenugopal Iyer 	}
888*0dc2366fSVenugopal Iyer 
889*0dc2366fSVenugopal Iyer 	ASSERT((udp_ringp != NULL) && (oth_ringp != NULL));
890*0dc2366fSVenugopal Iyer 
891*0dc2366fSVenugopal Iyer 	switch (stat) {
892*0dc2366fSVenugopal Iyer 	case MAC_STAT_RBYTES:
893*0dc2366fSVenugopal Iyer 		val = (tcp_ringp->s_ring_total_rbytes) +
894*0dc2366fSVenugopal Iyer 		    (udp_ringp->s_ring_total_rbytes) +
895*0dc2366fSVenugopal Iyer 		    (oth_ringp->s_ring_total_rbytes);
896*0dc2366fSVenugopal Iyer 		break;
897*0dc2366fSVenugopal Iyer 
898*0dc2366fSVenugopal Iyer 	case MAC_STAT_IPACKETS:
899*0dc2366fSVenugopal Iyer 		val = (tcp_ringp->s_ring_total_inpkt) +
900*0dc2366fSVenugopal Iyer 		    (udp_ringp->s_ring_total_inpkt) +
901*0dc2366fSVenugopal Iyer 		    (oth_ringp->s_ring_total_inpkt);
902*0dc2366fSVenugopal Iyer 		break;
903*0dc2366fSVenugopal Iyer 
904*0dc2366fSVenugopal Iyer 	default:
905*0dc2366fSVenugopal Iyer 		val = 0;
906*0dc2366fSVenugopal Iyer 		break;
907*0dc2366fSVenugopal Iyer 	}
908*0dc2366fSVenugopal Iyer 	mutex_exit(&mac_srs->srs_lock);
909*0dc2366fSVenugopal Iyer 	return (val);
910*0dc2366fSVenugopal Iyer }
911*0dc2366fSVenugopal Iyer 
912*0dc2366fSVenugopal Iyer static int
913*0dc2366fSVenugopal Iyer i_mac_rx_fanout_stat_update(kstat_t *ksp, int rw)
914*0dc2366fSVenugopal Iyer {
915*0dc2366fSVenugopal Iyer 	return (i_mac_stat_update(ksp, rw, i_mac_rx_fanout_stat_get,
916*0dc2366fSVenugopal Iyer 	    i_mac_rx_fanout_si, MAC_RX_FANOUT_NKSTAT));
917*0dc2366fSVenugopal Iyer }
918*0dc2366fSVenugopal Iyer 
919*0dc2366fSVenugopal Iyer static void
920*0dc2366fSVenugopal Iyer i_mac_rx_fanout_stat_create(mac_soft_ring_t *ringp, const char *modname,
921*0dc2366fSVenugopal Iyer     const char *statname)
922*0dc2366fSVenugopal Iyer {
923*0dc2366fSVenugopal Iyer 	kstat_t		*ksp;
924*0dc2366fSVenugopal Iyer 
925*0dc2366fSVenugopal Iyer 	ksp = i_mac_stat_create(ringp, modname, statname,
926*0dc2366fSVenugopal Iyer 	    i_mac_rx_fanout_stat_update, i_mac_rx_fanout_si,
927*0dc2366fSVenugopal Iyer 	    MAC_RX_FANOUT_NKSTAT);
928*0dc2366fSVenugopal Iyer 
929*0dc2366fSVenugopal Iyer 	ringp->s_ring_ksp = ksp;
930*0dc2366fSVenugopal Iyer }
931*0dc2366fSVenugopal Iyer 
9327c478bd9Sstevel@tonic-gate /*
9337c478bd9Sstevel@tonic-gate  * Exported functions.
9347c478bd9Sstevel@tonic-gate  */
9357c478bd9Sstevel@tonic-gate 
936ba2e4443Sseb /*
937ba2e4443Sseb  * Create the "mac" kstat.  The "mac" kstat is comprised of three kinds of
938ba2e4443Sseb  * statistics: statistics maintained by the mac module itself, generic mac
939ba2e4443Sseb  * statistics maintained by the driver, and MAC-type specific statistics
940ba2e4443Sseb  * also maintained by the driver.
941ba2e4443Sseb  */
9427c478bd9Sstevel@tonic-gate void
943*0dc2366fSVenugopal Iyer mac_driver_stat_create(mac_impl_t *mip)
9447c478bd9Sstevel@tonic-gate {
9457c478bd9Sstevel@tonic-gate 	kstat_t		*ksp;
9467c478bd9Sstevel@tonic-gate 	kstat_named_t	*knp;
9477c478bd9Sstevel@tonic-gate 	uint_t		count;
948d62bc4baSyz147064 	major_t		major = getmajor(mip->mi_phy_dev);
9497c478bd9Sstevel@tonic-gate 
950ba2e4443Sseb 	count = MAC_MOD_NKSTAT + MAC_NKSTAT + mip->mi_type->mt_statcount;
951d62bc4baSyz147064 	ksp = kstat_create((const char *)ddi_major_to_name(major),
952d62bc4baSyz147064 	    getminor(mip->mi_phy_dev) - 1, MAC_KSTAT_NAME,
953d624471bSelowe 	    MAC_KSTAT_CLASS, KSTAT_TYPE_NAMED, count, 0);
954ba2e4443Sseb 	if (ksp == NULL)
9557c478bd9Sstevel@tonic-gate 		return;
9567c478bd9Sstevel@tonic-gate 
957*0dc2366fSVenugopal Iyer 	ksp->ks_update = i_mac_driver_stat_update;
958ba2e4443Sseb 	ksp->ks_private = mip;
9597c478bd9Sstevel@tonic-gate 	mip->mi_ksp = ksp;
960ba2e4443Sseb 	mip->mi_kstat_count = count;
9617c478bd9Sstevel@tonic-gate 
9627c478bd9Sstevel@tonic-gate 	knp = (kstat_named_t *)ksp->ks_data;
963ba2e4443Sseb 	i_mac_kstat_init(knp, i_mac_mod_si, MAC_MOD_NKSTAT);
964ba2e4443Sseb 	knp += MAC_MOD_NKSTAT;
965ba2e4443Sseb 	i_mac_kstat_init(knp, i_mac_si, MAC_NKSTAT);
966ba2e4443Sseb 	if (mip->mi_type->mt_statcount > 0) {
967ba2e4443Sseb 		knp += MAC_NKSTAT;
968ba2e4443Sseb 		i_mac_kstat_init(knp, mip->mi_type->mt_stats,
969ba2e4443Sseb 		    mip->mi_type->mt_statcount);
9707c478bd9Sstevel@tonic-gate 	}
9717c478bd9Sstevel@tonic-gate 
9727c478bd9Sstevel@tonic-gate 	kstat_install(ksp);
9737c478bd9Sstevel@tonic-gate }
9747c478bd9Sstevel@tonic-gate 
9757c478bd9Sstevel@tonic-gate /*ARGSUSED*/
9767c478bd9Sstevel@tonic-gate void
977*0dc2366fSVenugopal Iyer mac_driver_stat_delete(mac_impl_t *mip)
9787c478bd9Sstevel@tonic-gate {
979ba2e4443Sseb 	if (mip->mi_ksp != NULL) {
9807c478bd9Sstevel@tonic-gate 		kstat_delete(mip->mi_ksp);
9817c478bd9Sstevel@tonic-gate 		mip->mi_ksp = NULL;
982ba2e4443Sseb 		mip->mi_kstat_count = 0;
983ba2e4443Sseb 	}
984ba2e4443Sseb }
985ba2e4443Sseb 
986ba2e4443Sseb uint64_t
987*0dc2366fSVenugopal Iyer mac_driver_stat_default(mac_impl_t *mip, uint_t stat)
988ba2e4443Sseb {
989ba2e4443Sseb 	uint_t	stat_index;
990ba2e4443Sseb 
991ba2e4443Sseb 	if (IS_MAC_STAT(stat)) {
992ba2e4443Sseb 		stat_index = stat - MAC_STAT_MIN;
993*0dc2366fSVenugopal Iyer 		ASSERT(stat_index < MAC_NKSTAT);
994ba2e4443Sseb 		return (i_mac_si[stat_index].msi_default);
995ba2e4443Sseb 	}
996ba2e4443Sseb 	ASSERT(IS_MACTYPE_STAT(stat));
997ba2e4443Sseb 	stat_index = stat - MACTYPE_STAT_MIN;
998*0dc2366fSVenugopal Iyer 	ASSERT(stat_index < mip->mi_type->mt_statcount);
999ba2e4443Sseb 	return (mip->mi_type->mt_stats[stat_index].msi_default);
10007c478bd9Sstevel@tonic-gate }
1001*0dc2366fSVenugopal Iyer 
1002*0dc2366fSVenugopal Iyer void
1003*0dc2366fSVenugopal Iyer mac_ring_stat_create(mac_ring_t *ring)
1004*0dc2366fSVenugopal Iyer {
1005*0dc2366fSVenugopal Iyer 	mac_impl_t	*mip = ring->mr_mip;
1006*0dc2366fSVenugopal Iyer 	char		statname[MAXNAMELEN];
1007*0dc2366fSVenugopal Iyer 	char		modname[MAXNAMELEN];
1008*0dc2366fSVenugopal Iyer 
1009*0dc2366fSVenugopal Iyer 	if (mip->mi_state_flags & MIS_IS_AGGR) {
1010*0dc2366fSVenugopal Iyer 		(void) strlcpy(modname, mip->mi_clients_list->mci_name,
1011*0dc2366fSVenugopal Iyer 		    MAXNAMELEN);
1012*0dc2366fSVenugopal Iyer 	} else
1013*0dc2366fSVenugopal Iyer 		(void) strlcpy(modname, mip->mi_name, MAXNAMELEN);
1014*0dc2366fSVenugopal Iyer 
1015*0dc2366fSVenugopal Iyer 	switch (ring->mr_type) {
1016*0dc2366fSVenugopal Iyer 	case MAC_RING_TYPE_RX:
1017*0dc2366fSVenugopal Iyer 		(void) snprintf(statname, sizeof (statname), "mac_rx_ring%d",
1018*0dc2366fSVenugopal Iyer 		    ring->mr_index);
1019*0dc2366fSVenugopal Iyer 		i_mac_rx_ring_stat_create(ring, modname, statname);
1020*0dc2366fSVenugopal Iyer 		break;
1021*0dc2366fSVenugopal Iyer 
1022*0dc2366fSVenugopal Iyer 	case MAC_RING_TYPE_TX:
1023*0dc2366fSVenugopal Iyer 		(void) snprintf(statname, sizeof (statname), "mac_tx_ring%d",
1024*0dc2366fSVenugopal Iyer 		    ring->mr_index);
1025*0dc2366fSVenugopal Iyer 		i_mac_tx_ring_stat_create(ring, modname, statname);
1026*0dc2366fSVenugopal Iyer 		break;
1027*0dc2366fSVenugopal Iyer 
1028*0dc2366fSVenugopal Iyer 	default:
1029*0dc2366fSVenugopal Iyer 		ASSERT(B_FALSE);
1030*0dc2366fSVenugopal Iyer 		break;
1031*0dc2366fSVenugopal Iyer 	}
1032*0dc2366fSVenugopal Iyer }
1033*0dc2366fSVenugopal Iyer 
1034*0dc2366fSVenugopal Iyer void
1035*0dc2366fSVenugopal Iyer mac_srs_stat_create(mac_soft_ring_set_t *mac_srs)
1036*0dc2366fSVenugopal Iyer {
1037*0dc2366fSVenugopal Iyer 	flow_entry_t	*flent = mac_srs->srs_flent;
1038*0dc2366fSVenugopal Iyer 	char 		statname[MAXNAMELEN];
1039*0dc2366fSVenugopal Iyer 	boolean_t	is_tx_srs;
1040*0dc2366fSVenugopal Iyer 
1041*0dc2366fSVenugopal Iyer 	/* No hardware/software lanes for user defined flows */
1042*0dc2366fSVenugopal Iyer 	if ((flent->fe_type & FLOW_USER) != 0)
1043*0dc2366fSVenugopal Iyer 		return;
1044*0dc2366fSVenugopal Iyer 
1045*0dc2366fSVenugopal Iyer 	is_tx_srs = ((mac_srs->srs_type & SRST_TX) != 0);
1046*0dc2366fSVenugopal Iyer 
1047*0dc2366fSVenugopal Iyer 	if (is_tx_srs) {
1048*0dc2366fSVenugopal Iyer 		mac_srs_tx_t	*srs_tx = &mac_srs->srs_tx;
1049*0dc2366fSVenugopal Iyer 		mac_ring_t	*ring = srs_tx->st_arg2;
1050*0dc2366fSVenugopal Iyer 
1051*0dc2366fSVenugopal Iyer 		if (ring != NULL) {
1052*0dc2366fSVenugopal Iyer 			(void) snprintf(statname, sizeof (statname),
1053*0dc2366fSVenugopal Iyer 			    "mac_tx_hwlane%d", ring->mr_index);
1054*0dc2366fSVenugopal Iyer 		} else {
1055*0dc2366fSVenugopal Iyer 			(void) snprintf(statname, sizeof (statname),
1056*0dc2366fSVenugopal Iyer 			    "mac_tx_swlane0");
1057*0dc2366fSVenugopal Iyer 		}
1058*0dc2366fSVenugopal Iyer 		i_mac_tx_swlane_stat_create(mac_srs, flent->fe_flow_name,
1059*0dc2366fSVenugopal Iyer 		    statname);
1060*0dc2366fSVenugopal Iyer 	} else {
1061*0dc2366fSVenugopal Iyer 		mac_ring_t	*ring = mac_srs->srs_ring;
1062*0dc2366fSVenugopal Iyer 
1063*0dc2366fSVenugopal Iyer 		if (ring == NULL) {
1064*0dc2366fSVenugopal Iyer 			(void) snprintf(statname, sizeof (statname),
1065*0dc2366fSVenugopal Iyer 			    "mac_rx_swlane0");
1066*0dc2366fSVenugopal Iyer 			i_mac_rx_swlane_stat_create(mac_srs,
1067*0dc2366fSVenugopal Iyer 			    flent->fe_flow_name, statname);
1068*0dc2366fSVenugopal Iyer 		} else {
1069*0dc2366fSVenugopal Iyer 			(void) snprintf(statname, sizeof (statname),
1070*0dc2366fSVenugopal Iyer 			    "mac_rx_hwlane%d", ring->mr_index);
1071*0dc2366fSVenugopal Iyer 			i_mac_rx_hwlane_stat_create(mac_srs,
1072*0dc2366fSVenugopal Iyer 			    flent->fe_flow_name, statname);
1073*0dc2366fSVenugopal Iyer 		}
1074*0dc2366fSVenugopal Iyer 	}
1075*0dc2366fSVenugopal Iyer }
1076*0dc2366fSVenugopal Iyer 
1077*0dc2366fSVenugopal Iyer void
1078*0dc2366fSVenugopal Iyer mac_misc_stat_create(flow_entry_t *flent)
1079*0dc2366fSVenugopal Iyer {
1080*0dc2366fSVenugopal Iyer 	char	statname[MAXNAMELEN];
1081*0dc2366fSVenugopal Iyer 
1082*0dc2366fSVenugopal Iyer 	/* No misc stats for user defined or mcast/bcast flows */
1083*0dc2366fSVenugopal Iyer 	if (((flent->fe_type & FLOW_USER) != 0) ||
1084*0dc2366fSVenugopal Iyer 	    ((flent->fe_type & FLOW_MCAST) != 0))
1085*0dc2366fSVenugopal Iyer 		return;
1086*0dc2366fSVenugopal Iyer 
1087*0dc2366fSVenugopal Iyer 	(void) snprintf(statname, sizeof (statname), "mac_misc_stat");
1088*0dc2366fSVenugopal Iyer 	i_mac_misc_stat_create(flent, flent->fe_flow_name, statname);
1089*0dc2366fSVenugopal Iyer }
1090*0dc2366fSVenugopal Iyer 
1091*0dc2366fSVenugopal Iyer void
1092*0dc2366fSVenugopal Iyer mac_soft_ring_stat_create(mac_soft_ring_t *ringp)
1093*0dc2366fSVenugopal Iyer {
1094*0dc2366fSVenugopal Iyer 	mac_soft_ring_set_t	*mac_srs = ringp->s_ring_set;
1095*0dc2366fSVenugopal Iyer 	flow_entry_t		*flent = ringp->s_ring_mcip->mci_flent;
1096*0dc2366fSVenugopal Iyer 	mac_ring_t		*ring = (mac_ring_t *)ringp->s_ring_tx_arg2;
1097*0dc2366fSVenugopal Iyer 	boolean_t		is_tx_srs;
1098*0dc2366fSVenugopal Iyer 	char			statname[MAXNAMELEN];
1099*0dc2366fSVenugopal Iyer 
1100*0dc2366fSVenugopal Iyer 	/* No hardware/software lanes for user defined flows */
1101*0dc2366fSVenugopal Iyer 	if ((flent->fe_type & FLOW_USER) != 0)
1102*0dc2366fSVenugopal Iyer 		return;
1103*0dc2366fSVenugopal Iyer 
1104*0dc2366fSVenugopal Iyer 	is_tx_srs = ((mac_srs->srs_type & SRST_TX) != 0);
1105*0dc2366fSVenugopal Iyer 	if (is_tx_srs) {	/* tx side hardware lane */
1106*0dc2366fSVenugopal Iyer 		ASSERT(ring != NULL);
1107*0dc2366fSVenugopal Iyer 		(void) snprintf(statname, sizeof (statname), "mac_tx_hwlane%d",
1108*0dc2366fSVenugopal Iyer 		    ring->mr_index);
1109*0dc2366fSVenugopal Iyer 		i_mac_tx_hwlane_stat_create(ringp, flent->fe_flow_name,
1110*0dc2366fSVenugopal Iyer 		    statname);
1111*0dc2366fSVenugopal Iyer 	} else {		/* rx side fanout */
1112*0dc2366fSVenugopal Iyer 				/* Maintain single stat for (tcp, udp, oth) */
1113*0dc2366fSVenugopal Iyer 		if (ringp->s_ring_type & ST_RING_TCP) {
1114*0dc2366fSVenugopal Iyer 			int			index;
1115*0dc2366fSVenugopal Iyer 			mac_soft_ring_t		*softring;
1116*0dc2366fSVenugopal Iyer 
1117*0dc2366fSVenugopal Iyer 			for (index = 0, softring = mac_srs->srs_soft_ring_head;
1118*0dc2366fSVenugopal Iyer 			    softring != NULL;
1119*0dc2366fSVenugopal Iyer 			    index++, softring = softring->s_ring_next) {
1120*0dc2366fSVenugopal Iyer 				if (softring == ringp)
1121*0dc2366fSVenugopal Iyer 					break;
1122*0dc2366fSVenugopal Iyer 			}
1123*0dc2366fSVenugopal Iyer 
1124*0dc2366fSVenugopal Iyer 			if (mac_srs->srs_ring == NULL) {
1125*0dc2366fSVenugopal Iyer 				(void) snprintf(statname, sizeof (statname),
1126*0dc2366fSVenugopal Iyer 				    "mac_rx_swlane0_fanout%d", index/3);
1127*0dc2366fSVenugopal Iyer 			} else {
1128*0dc2366fSVenugopal Iyer 				(void) snprintf(statname, sizeof (statname),
1129*0dc2366fSVenugopal Iyer 				    "mac_rx_hwlane%d_fanout%d",
1130*0dc2366fSVenugopal Iyer 				    mac_srs->srs_ring->mr_index, index/3);
1131*0dc2366fSVenugopal Iyer 			}
1132*0dc2366fSVenugopal Iyer 			i_mac_rx_fanout_stat_create(ringp, flent->fe_flow_name,
1133*0dc2366fSVenugopal Iyer 			    statname);
1134*0dc2366fSVenugopal Iyer 		}
1135*0dc2366fSVenugopal Iyer 	}
1136*0dc2366fSVenugopal Iyer }
1137*0dc2366fSVenugopal Iyer 
1138*0dc2366fSVenugopal Iyer void
1139*0dc2366fSVenugopal Iyer mac_ring_stat_delete(mac_ring_t *ring)
1140*0dc2366fSVenugopal Iyer {
1141*0dc2366fSVenugopal Iyer 	if (ring->mr_ksp != NULL) {
1142*0dc2366fSVenugopal Iyer 		kstat_delete(ring->mr_ksp);
1143*0dc2366fSVenugopal Iyer 		ring->mr_ksp = NULL;
1144*0dc2366fSVenugopal Iyer 	}
1145*0dc2366fSVenugopal Iyer }
1146*0dc2366fSVenugopal Iyer 
1147*0dc2366fSVenugopal Iyer void
1148*0dc2366fSVenugopal Iyer mac_srs_stat_delete(mac_soft_ring_set_t *mac_srs)
1149*0dc2366fSVenugopal Iyer {
1150*0dc2366fSVenugopal Iyer 	boolean_t	is_tx_srs;
1151*0dc2366fSVenugopal Iyer 
1152*0dc2366fSVenugopal Iyer 	is_tx_srs = ((mac_srs->srs_type & SRST_TX) != 0);
1153*0dc2366fSVenugopal Iyer 	if (!is_tx_srs) {
1154*0dc2366fSVenugopal Iyer 		/*
1155*0dc2366fSVenugopal Iyer 		 * Rx ring has been taken away. Before destroying corresponding
1156*0dc2366fSVenugopal Iyer 		 * SRS, save the stats recorded by that SRS.
1157*0dc2366fSVenugopal Iyer 		 */
1158*0dc2366fSVenugopal Iyer 		mac_client_impl_t	*mcip = mac_srs->srs_mcip;
1159*0dc2366fSVenugopal Iyer 		mac_misc_stats_t	*mac_misc_stat = &mcip->mci_misc_stat;
1160*0dc2366fSVenugopal Iyer 		mac_rx_stats_t		*mac_rx_stat = &mac_srs->srs_rx.sr_stat;
1161*0dc2366fSVenugopal Iyer 
1162*0dc2366fSVenugopal Iyer 		i_mac_add_stats(&mac_misc_stat->mms_defunctrxlanestats,
1163*0dc2366fSVenugopal Iyer 		    mac_rx_stat, &mac_misc_stat->mms_defunctrxlanestats,
1164*0dc2366fSVenugopal Iyer 		    rx_srs_stats_list, RX_SRS_STAT_SIZE);
1165*0dc2366fSVenugopal Iyer 	}
1166*0dc2366fSVenugopal Iyer 
1167*0dc2366fSVenugopal Iyer 	if (mac_srs->srs_ksp != NULL) {
1168*0dc2366fSVenugopal Iyer 		kstat_delete(mac_srs->srs_ksp);
1169*0dc2366fSVenugopal Iyer 		mac_srs->srs_ksp = NULL;
1170*0dc2366fSVenugopal Iyer 	}
1171*0dc2366fSVenugopal Iyer }
1172*0dc2366fSVenugopal Iyer 
1173*0dc2366fSVenugopal Iyer void
1174*0dc2366fSVenugopal Iyer mac_misc_stat_delete(flow_entry_t *flent)
1175*0dc2366fSVenugopal Iyer {
1176*0dc2366fSVenugopal Iyer 	if (flent->fe_misc_stat_ksp != NULL) {
1177*0dc2366fSVenugopal Iyer 		kstat_delete(flent->fe_misc_stat_ksp);
1178*0dc2366fSVenugopal Iyer 		flent->fe_misc_stat_ksp = NULL;
1179*0dc2366fSVenugopal Iyer 	}
1180*0dc2366fSVenugopal Iyer }
1181*0dc2366fSVenugopal Iyer 
1182*0dc2366fSVenugopal Iyer void
1183*0dc2366fSVenugopal Iyer mac_soft_ring_stat_delete(mac_soft_ring_t *ringp)
1184*0dc2366fSVenugopal Iyer {
1185*0dc2366fSVenugopal Iyer 	mac_soft_ring_set_t	*mac_srs = ringp->s_ring_set;
1186*0dc2366fSVenugopal Iyer 	boolean_t		is_tx_srs;
1187*0dc2366fSVenugopal Iyer 
1188*0dc2366fSVenugopal Iyer 	is_tx_srs = ((mac_srs->srs_type & SRST_TX) != 0);
1189*0dc2366fSVenugopal Iyer 	if (is_tx_srs) {
1190*0dc2366fSVenugopal Iyer 		/*
1191*0dc2366fSVenugopal Iyer 		 * Tx ring has been taken away. Before destroying corresponding
1192*0dc2366fSVenugopal Iyer 		 * soft ring, save the stats recorded by that soft ring.
1193*0dc2366fSVenugopal Iyer 		 */
1194*0dc2366fSVenugopal Iyer 		mac_client_impl_t	*mcip = mac_srs->srs_mcip;
1195*0dc2366fSVenugopal Iyer 		mac_misc_stats_t	*mac_misc_stat = &mcip->mci_misc_stat;
1196*0dc2366fSVenugopal Iyer 		mac_tx_stats_t		*mac_tx_stat = &ringp->s_st_stat;
1197*0dc2366fSVenugopal Iyer 
1198*0dc2366fSVenugopal Iyer 		i_mac_add_stats(&mac_misc_stat->mms_defuncttxlanestats,
1199*0dc2366fSVenugopal Iyer 		    mac_tx_stat, &mac_misc_stat->mms_defuncttxlanestats,
1200*0dc2366fSVenugopal Iyer 		    tx_softring_stats_list, TX_SOFTRING_STAT_SIZE);
1201*0dc2366fSVenugopal Iyer 	}
1202*0dc2366fSVenugopal Iyer 
1203*0dc2366fSVenugopal Iyer 	if (ringp->s_ring_ksp) {
1204*0dc2366fSVenugopal Iyer 		kstat_delete(ringp->s_ring_ksp);
1205*0dc2366fSVenugopal Iyer 		ringp->s_ring_ksp = NULL;
1206*0dc2366fSVenugopal Iyer 	}
1207*0dc2366fSVenugopal Iyer }
1208*0dc2366fSVenugopal Iyer 
1209*0dc2366fSVenugopal Iyer void
1210*0dc2366fSVenugopal Iyer mac_pseudo_ring_stat_rename(mac_impl_t *mip)
1211*0dc2366fSVenugopal Iyer {
1212*0dc2366fSVenugopal Iyer 	mac_group_t	*group;
1213*0dc2366fSVenugopal Iyer 	mac_ring_t	*ring;
1214*0dc2366fSVenugopal Iyer 
1215*0dc2366fSVenugopal Iyer 	/* Recreate pseudo rx ring kstats */
1216*0dc2366fSVenugopal Iyer 	for (group = mip->mi_rx_groups; group != NULL;
1217*0dc2366fSVenugopal Iyer 	    group = group->mrg_next) {
1218*0dc2366fSVenugopal Iyer 		for (ring = group->mrg_rings; ring != NULL;
1219*0dc2366fSVenugopal Iyer 		    ring = ring->mr_next) {
1220*0dc2366fSVenugopal Iyer 			mac_ring_stat_delete(ring);
1221*0dc2366fSVenugopal Iyer 			mac_ring_stat_create(ring);
1222*0dc2366fSVenugopal Iyer 		}
1223*0dc2366fSVenugopal Iyer 	}
1224*0dc2366fSVenugopal Iyer 
1225*0dc2366fSVenugopal Iyer 	/* Recreate pseudo tx ring kstats */
1226*0dc2366fSVenugopal Iyer 	for (group = mip->mi_tx_groups; group != NULL;
1227*0dc2366fSVenugopal Iyer 	    group = group->mrg_next) {
1228*0dc2366fSVenugopal Iyer 		for (ring = group->mrg_rings; ring != NULL;
1229*0dc2366fSVenugopal Iyer 		    ring = ring->mr_next) {
1230*0dc2366fSVenugopal Iyer 			mac_ring_stat_delete(ring);
1231*0dc2366fSVenugopal Iyer 			mac_ring_stat_create(ring);
1232*0dc2366fSVenugopal Iyer 		}
1233*0dc2366fSVenugopal Iyer 	}
1234*0dc2366fSVenugopal Iyer }
1235*0dc2366fSVenugopal Iyer 
1236*0dc2366fSVenugopal Iyer void
1237*0dc2366fSVenugopal Iyer mac_stat_rename(mac_client_impl_t *mcip)
1238*0dc2366fSVenugopal Iyer {
1239*0dc2366fSVenugopal Iyer 	flow_entry_t		*flent = mcip->mci_flent;
1240*0dc2366fSVenugopal Iyer 	mac_soft_ring_set_t	*mac_srs;
1241*0dc2366fSVenugopal Iyer 	mac_soft_ring_t		*ringp;
1242*0dc2366fSVenugopal Iyer 	int			i, j;
1243*0dc2366fSVenugopal Iyer 
1244*0dc2366fSVenugopal Iyer 	ASSERT(flent != NULL);
1245*0dc2366fSVenugopal Iyer 
1246*0dc2366fSVenugopal Iyer 	/* Recreate rx SRSes kstats */
1247*0dc2366fSVenugopal Iyer 	for (i = 0; i < flent->fe_rx_srs_cnt; i++) {
1248*0dc2366fSVenugopal Iyer 		mac_srs = (mac_soft_ring_set_t *)flent->fe_rx_srs[i];
1249*0dc2366fSVenugopal Iyer 		mac_srs_stat_delete(mac_srs);
1250*0dc2366fSVenugopal Iyer 		mac_srs_stat_create(mac_srs);
1251*0dc2366fSVenugopal Iyer 
1252*0dc2366fSVenugopal Iyer 		/* Recreate rx fanout kstats */
1253*0dc2366fSVenugopal Iyer 		for (j = 0; j < mac_srs->srs_tcp_ring_count; j++) {
1254*0dc2366fSVenugopal Iyer 			ringp = mac_srs->srs_tcp_soft_rings[j];
1255*0dc2366fSVenugopal Iyer 			mac_soft_ring_stat_delete(ringp);
1256*0dc2366fSVenugopal Iyer 			mac_soft_ring_stat_create(ringp);
1257*0dc2366fSVenugopal Iyer 		}
1258*0dc2366fSVenugopal Iyer 	}
1259*0dc2366fSVenugopal Iyer 
1260*0dc2366fSVenugopal Iyer 	/* Recreate tx SRS kstats */
1261*0dc2366fSVenugopal Iyer 	mac_srs = (mac_soft_ring_set_t *)flent->fe_tx_srs;
1262*0dc2366fSVenugopal Iyer 	mac_srs_stat_delete(mac_srs);
1263*0dc2366fSVenugopal Iyer 	mac_srs_stat_create(mac_srs);
1264*0dc2366fSVenugopal Iyer 
1265*0dc2366fSVenugopal Iyer 	/* Recreate tx sofring kstats */
1266*0dc2366fSVenugopal Iyer 	for (ringp = mac_srs->srs_soft_ring_head; ringp;
1267*0dc2366fSVenugopal Iyer 	    ringp = ringp->s_ring_next) {
1268*0dc2366fSVenugopal Iyer 		mac_soft_ring_stat_delete(ringp);
1269*0dc2366fSVenugopal Iyer 		mac_soft_ring_stat_create(ringp);
1270*0dc2366fSVenugopal Iyer 	}
1271*0dc2366fSVenugopal Iyer 
1272*0dc2366fSVenugopal Iyer 	/* Recreate misc kstats */
1273*0dc2366fSVenugopal Iyer 	mac_misc_stat_delete(flent);
1274*0dc2366fSVenugopal Iyer 	mac_misc_stat_create(flent);
1275*0dc2366fSVenugopal Iyer }
1276*0dc2366fSVenugopal Iyer 
1277*0dc2366fSVenugopal Iyer void
1278*0dc2366fSVenugopal Iyer mac_tx_srs_stat_recreate(mac_soft_ring_set_t *tx_srs, boolean_t add_stats)
1279*0dc2366fSVenugopal Iyer {
1280*0dc2366fSVenugopal Iyer 	mac_client_impl_t	*mcip = tx_srs->srs_mcip;
1281*0dc2366fSVenugopal Iyer 	mac_misc_stats_t	*mac_misc_stat = &mcip->mci_misc_stat;
1282*0dc2366fSVenugopal Iyer 	mac_tx_stats_t		*mac_tx_stat = &tx_srs->srs_tx.st_stat;
1283*0dc2366fSVenugopal Iyer 
1284*0dc2366fSVenugopal Iyer 	if (add_stats) {
1285*0dc2366fSVenugopal Iyer 		/* Add the stats to cumulative stats */
1286*0dc2366fSVenugopal Iyer 		i_mac_add_stats(&mac_misc_stat->mms_defuncttxlanestats,
1287*0dc2366fSVenugopal Iyer 		    mac_tx_stat, &mac_misc_stat->mms_defuncttxlanestats,
1288*0dc2366fSVenugopal Iyer 		    tx_softring_stats_list, TX_SOFTRING_STAT_SIZE);
1289*0dc2366fSVenugopal Iyer 	}
1290*0dc2366fSVenugopal Iyer 
1291*0dc2366fSVenugopal Iyer 	bzero(mac_tx_stat, sizeof (mac_tx_stats_t));
1292*0dc2366fSVenugopal Iyer 	mac_srs_stat_delete(tx_srs);
1293*0dc2366fSVenugopal Iyer 	mac_srs_stat_create(tx_srs);
1294*0dc2366fSVenugopal Iyer }
1295