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