xref: /titanic_41/usr/src/lib/libdladm/common/libdlstat.h (revision 0dc2366f7b9f9f36e10909b1e95edbf2a261c2ac)
1da14cebeSEric Cheng /*
2da14cebeSEric Cheng  * CDDL HEADER START
3da14cebeSEric Cheng  *
4da14cebeSEric Cheng  * The contents of this file are subject to the terms of the
5da14cebeSEric Cheng  * Common Development and Distribution License (the "License").
6da14cebeSEric Cheng  * You may not use this file except in compliance with the License.
7da14cebeSEric Cheng  *
8da14cebeSEric Cheng  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9da14cebeSEric Cheng  * or http://www.opensolaris.org/os/licensing.
10da14cebeSEric Cheng  * See the License for the specific language governing permissions
11da14cebeSEric Cheng  * and limitations under the License.
12da14cebeSEric Cheng  *
13da14cebeSEric Cheng  * When distributing Covered Code, include this CDDL HEADER in each
14da14cebeSEric Cheng  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15da14cebeSEric Cheng  * If applicable, add the following below this CDDL HEADER, with the
16da14cebeSEric Cheng  * fields enclosed by brackets "[]" replaced with your own identifying
17da14cebeSEric Cheng  * information: Portions Copyright [yyyy] [name of copyright owner]
18da14cebeSEric Cheng  *
19da14cebeSEric Cheng  * CDDL HEADER END
20da14cebeSEric Cheng  */
21da14cebeSEric Cheng /*
22*0dc2366fSVenugopal Iyer  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23da14cebeSEric Cheng  * Use is subject to license terms.
24da14cebeSEric Cheng  */
25da14cebeSEric Cheng 
26da14cebeSEric Cheng #ifndef _LIBDLSTAT_H
27da14cebeSEric Cheng #define	_LIBDLSTAT_H
28da14cebeSEric Cheng 
29da14cebeSEric Cheng /*
30da14cebeSEric Cheng  * This file includes structures, macros and common routines shared by all
31da14cebeSEric Cheng  * data-link administration, and routines which are used to retrieve and
32da14cebeSEric Cheng  * display statistics.
33da14cebeSEric Cheng  */
34da14cebeSEric Cheng 
35da14cebeSEric Cheng #include <kstat.h>
36da14cebeSEric Cheng 
37da14cebeSEric Cheng #ifdef	__cplusplus
38da14cebeSEric Cheng extern "C" {
39da14cebeSEric Cheng #endif
40da14cebeSEric Cheng 
41da14cebeSEric Cheng #define	LINK_REPORT	1
42da14cebeSEric Cheng #define	FLOW_REPORT	2
43da14cebeSEric Cheng 
44*0dc2366fSVenugopal Iyer #define	DLSTAT_INVALID_ENTRY	-1
45*0dc2366fSVenugopal Iyer #define	MAXSTATNAMELEN	256
46*0dc2366fSVenugopal Iyer /*
47*0dc2366fSVenugopal Iyer  * Definitions common to all stats
48*0dc2366fSVenugopal Iyer  */
49*0dc2366fSVenugopal Iyer typedef struct dladm_stat_chain_s {
50*0dc2366fSVenugopal Iyer 	char				dc_statheader[MAXSTATNAMELEN];
51*0dc2366fSVenugopal Iyer 	void				*dc_statentry;
52*0dc2366fSVenugopal Iyer 	struct dladm_stat_chain_s	*dc_next;
53*0dc2366fSVenugopal Iyer } dladm_stat_chain_t;
54*0dc2366fSVenugopal Iyer 
55*0dc2366fSVenugopal Iyer typedef enum {
56*0dc2366fSVenugopal Iyer 	DLADM_STAT_RX_LANE = 0,		/* Per lane rx stats */
57*0dc2366fSVenugopal Iyer 	DLADM_STAT_TX_LANE,		/* Per lane tx stats */
58*0dc2366fSVenugopal Iyer 	DLADM_STAT_RX_LANE_TOTAL,	/* Stats summed across all rx lanes */
59*0dc2366fSVenugopal Iyer 	DLADM_STAT_TX_LANE_TOTAL,	/* Stats summed across all tx lanes */
60*0dc2366fSVenugopal Iyer 	DLADM_STAT_RX_LANE_FOUT,	/* Per fanout (rx lane) stats */
61*0dc2366fSVenugopal Iyer 	DLADM_STAT_RX_RING,		/* Per ring rx stats */
62*0dc2366fSVenugopal Iyer 	DLADM_STAT_TX_RING,		/* Per ring tx stats  */
63*0dc2366fSVenugopal Iyer 	DLADM_STAT_RX_RING_TOTAL,	/* Stats summed across all rx rings */
64*0dc2366fSVenugopal Iyer 	DLADM_STAT_TX_RING_TOTAL,	/* Stats summed across all tx rings */
65*0dc2366fSVenugopal Iyer 	DLADM_STAT_TOTAL,		/* Summary view */
66*0dc2366fSVenugopal Iyer 	DLADM_STAT_AGGR_PORT,		/* Aggr port stats */
67*0dc2366fSVenugopal Iyer 	DLADM_STAT_MISC,		/* Misc stats */
68*0dc2366fSVenugopal Iyer 	DLADM_STAT_NUM_STATS		/* This must always be the last entry */
69*0dc2366fSVenugopal Iyer } dladm_stat_type_t;
70*0dc2366fSVenugopal Iyer 
71*0dc2366fSVenugopal Iyer /*
72*0dc2366fSVenugopal Iyer  * Definitions for rx lane stats
73*0dc2366fSVenugopal Iyer  */
74*0dc2366fSVenugopal Iyer typedef struct rx_lane_stat_s {
75*0dc2366fSVenugopal Iyer 	uint64_t	rl_ipackets;
76*0dc2366fSVenugopal Iyer 	uint64_t	rl_rbytes;
77*0dc2366fSVenugopal Iyer 	uint64_t	rl_lclpackets;
78*0dc2366fSVenugopal Iyer 	uint64_t	rl_lclbytes;
79*0dc2366fSVenugopal Iyer 	uint64_t	rl_intrs;
80*0dc2366fSVenugopal Iyer 	uint64_t	rl_intrbytes;
81*0dc2366fSVenugopal Iyer 	uint64_t	rl_pollbytes;
82*0dc2366fSVenugopal Iyer 	uint64_t	rl_polls;
83*0dc2366fSVenugopal Iyer 	uint64_t	rl_sdrops;
84*0dc2366fSVenugopal Iyer 	uint64_t	rl_chl10;
85*0dc2366fSVenugopal Iyer 	uint64_t	rl_ch10_50;
86*0dc2366fSVenugopal Iyer 	uint64_t	rl_chg50;
87*0dc2366fSVenugopal Iyer } rx_lane_stat_t;
88*0dc2366fSVenugopal Iyer 
89*0dc2366fSVenugopal Iyer typedef enum {
90*0dc2366fSVenugopal Iyer 	L_HWLANE,
91*0dc2366fSVenugopal Iyer 	L_SWLANE,
92*0dc2366fSVenugopal Iyer 	L_LOCAL,
93*0dc2366fSVenugopal Iyer 	L_LCLSWLANE,
94*0dc2366fSVenugopal Iyer 	L_BCAST,
95*0dc2366fSVenugopal Iyer 	L_DFNCT
96*0dc2366fSVenugopal Iyer } lane_type_t;
97*0dc2366fSVenugopal Iyer 
98*0dc2366fSVenugopal Iyer typedef struct rx_lane_stat_entry_s {
99*0dc2366fSVenugopal Iyer 	int64_t		rle_index;
100*0dc2366fSVenugopal Iyer 	lane_type_t	rle_id;
101*0dc2366fSVenugopal Iyer 	rx_lane_stat_t	rle_stats;
102*0dc2366fSVenugopal Iyer } rx_lane_stat_entry_t;
103*0dc2366fSVenugopal Iyer 
104*0dc2366fSVenugopal Iyer /*
105*0dc2366fSVenugopal Iyer  * Definitions for tx lane stats
106*0dc2366fSVenugopal Iyer  */
107*0dc2366fSVenugopal Iyer typedef struct tx_lane_stat_s {
108*0dc2366fSVenugopal Iyer 	uint64_t	tl_opackets;
109*0dc2366fSVenugopal Iyer 	uint64_t	tl_obytes;
110*0dc2366fSVenugopal Iyer 	uint64_t	tl_blockcnt;
111*0dc2366fSVenugopal Iyer 	uint64_t	tl_unblockcnt;
112*0dc2366fSVenugopal Iyer 	uint64_t	tl_sdrops;
113*0dc2366fSVenugopal Iyer } tx_lane_stat_t;
114*0dc2366fSVenugopal Iyer 
115*0dc2366fSVenugopal Iyer typedef struct tx_lane_stat_entry_s {
116*0dc2366fSVenugopal Iyer 	int64_t		tle_index;
117*0dc2366fSVenugopal Iyer 	lane_type_t	tle_id;
118*0dc2366fSVenugopal Iyer 	tx_lane_stat_t	tle_stats;
119*0dc2366fSVenugopal Iyer } tx_lane_stat_entry_t;
120*0dc2366fSVenugopal Iyer 
121*0dc2366fSVenugopal Iyer /*
122*0dc2366fSVenugopal Iyer  * Definitions for tx/rx misc stats
123*0dc2366fSVenugopal Iyer  */
124*0dc2366fSVenugopal Iyer typedef struct misc_stat_s {
125*0dc2366fSVenugopal Iyer 	uint64_t	ms_multircv;
126*0dc2366fSVenugopal Iyer 	uint64_t	ms_brdcstrcv;
127*0dc2366fSVenugopal Iyer 	uint64_t	ms_multixmt;
128*0dc2366fSVenugopal Iyer 	uint64_t	ms_brdcstxmt;
129*0dc2366fSVenugopal Iyer 	uint64_t	ms_multircvbytes;
130*0dc2366fSVenugopal Iyer 	uint64_t	ms_brdcstrcvbytes;
131*0dc2366fSVenugopal Iyer 	uint64_t	ms_multixmtbytes;
132*0dc2366fSVenugopal Iyer 	uint64_t	ms_brdcstxmtbytes;
133*0dc2366fSVenugopal Iyer 	uint64_t	ms_txerrors;
134*0dc2366fSVenugopal Iyer 	uint64_t	ms_macspoofed;
135*0dc2366fSVenugopal Iyer 	uint64_t	ms_ipspoofed;
136*0dc2366fSVenugopal Iyer 	uint64_t	ms_dhcpspoofed;
137*0dc2366fSVenugopal Iyer 	uint64_t	ms_restricted;
138*0dc2366fSVenugopal Iyer 	uint64_t	ms_dhcpdropped;
139*0dc2366fSVenugopal Iyer 	uint64_t	ms_ipackets;
140*0dc2366fSVenugopal Iyer 	uint64_t	ms_rbytes;
141*0dc2366fSVenugopal Iyer 	uint64_t	ms_local;
142*0dc2366fSVenugopal Iyer 	uint64_t	ms_localbytes;
143*0dc2366fSVenugopal Iyer 	uint64_t	ms_intrs;
144*0dc2366fSVenugopal Iyer 	uint64_t	ms_intrbytes;
145*0dc2366fSVenugopal Iyer 	uint64_t	ms_polls;
146*0dc2366fSVenugopal Iyer 	uint64_t	ms_pollbytes;
147*0dc2366fSVenugopal Iyer 	uint64_t	ms_rxsdrops;
148*0dc2366fSVenugopal Iyer 	uint64_t	ms_chainunder10;
149*0dc2366fSVenugopal Iyer 	uint64_t	ms_chain10to50;
150*0dc2366fSVenugopal Iyer 	uint64_t	ms_chainover50;
151*0dc2366fSVenugopal Iyer 	uint64_t	ms_obytes;
152*0dc2366fSVenugopal Iyer 	uint64_t	ms_opackets;
153*0dc2366fSVenugopal Iyer 	uint64_t	ms_blockcnt;
154*0dc2366fSVenugopal Iyer 	uint64_t	ms_unblockcnt;
155*0dc2366fSVenugopal Iyer 	uint64_t	ms_txsdrops;
156*0dc2366fSVenugopal Iyer } misc_stat_t;
157*0dc2366fSVenugopal Iyer 
158*0dc2366fSVenugopal Iyer /*
159*0dc2366fSVenugopal Iyer  * To be consistent with other stat entries, misc stat
160*0dc2366fSVenugopal Iyer  * is wrapped in stat entry
161*0dc2366fSVenugopal Iyer  */
162*0dc2366fSVenugopal Iyer typedef struct misc_stat_entry_s {
163*0dc2366fSVenugopal Iyer 	misc_stat_t	mse_stats;
164*0dc2366fSVenugopal Iyer } misc_stat_entry_t;
165*0dc2366fSVenugopal Iyer 
166*0dc2366fSVenugopal Iyer /*
167*0dc2366fSVenugopal Iyer  * Definitions for ring stats: used by rx as well as tx
168*0dc2366fSVenugopal Iyer  */
169*0dc2366fSVenugopal Iyer typedef struct ring_stat_s {
170*0dc2366fSVenugopal Iyer 	uint64_t	r_packets;
171*0dc2366fSVenugopal Iyer 	uint64_t	r_bytes;
172*0dc2366fSVenugopal Iyer } ring_stat_t;
173*0dc2366fSVenugopal Iyer 
174*0dc2366fSVenugopal Iyer typedef struct ring_stat_entry_s {
175*0dc2366fSVenugopal Iyer 	int64_t		re_index;
176*0dc2366fSVenugopal Iyer 	ring_stat_t	re_stats;
177*0dc2366fSVenugopal Iyer } ring_stat_entry_t;
178*0dc2366fSVenugopal Iyer 
179*0dc2366fSVenugopal Iyer /*
180*0dc2366fSVenugopal Iyer  * Definitions for fanout stats
181*0dc2366fSVenugopal Iyer  */
182*0dc2366fSVenugopal Iyer typedef struct fanout_stat_s {
183*0dc2366fSVenugopal Iyer 	uint64_t	f_ipackets;
184*0dc2366fSVenugopal Iyer 	uint64_t	f_rbytes;
185*0dc2366fSVenugopal Iyer } fanout_stat_t;
186*0dc2366fSVenugopal Iyer 
187*0dc2366fSVenugopal Iyer typedef struct fanout_stat_entry_s {
188*0dc2366fSVenugopal Iyer 	int64_t		fe_index;
189*0dc2366fSVenugopal Iyer 	lane_type_t	fe_id;		/* hw, sw, local */
190*0dc2366fSVenugopal Iyer 	int64_t		fe_foutindex;	/* fanout index */
191*0dc2366fSVenugopal Iyer 	fanout_stat_t	fe_stats;
192*0dc2366fSVenugopal Iyer } fanout_stat_entry_t;
193*0dc2366fSVenugopal Iyer 
194*0dc2366fSVenugopal Iyer /*
195*0dc2366fSVenugopal Iyer  * Definitions for total stats
196*0dc2366fSVenugopal Iyer  */
197*0dc2366fSVenugopal Iyer typedef struct total_stat_s {
198*0dc2366fSVenugopal Iyer 	uint64_t	ts_ipackets;
199*0dc2366fSVenugopal Iyer 	uint64_t	ts_rbytes;
200*0dc2366fSVenugopal Iyer 	uint64_t	ts_opackets;
201*0dc2366fSVenugopal Iyer 	uint64_t	ts_obytes;
202*0dc2366fSVenugopal Iyer } total_stat_t;
203*0dc2366fSVenugopal Iyer 
204*0dc2366fSVenugopal Iyer /*
205*0dc2366fSVenugopal Iyer  * To be consistent with other stat entries, total stat
206*0dc2366fSVenugopal Iyer  * is wrapped in stat entry
207*0dc2366fSVenugopal Iyer  */
208*0dc2366fSVenugopal Iyer typedef struct total_stat_entry_s {
209*0dc2366fSVenugopal Iyer 	total_stat_t	tse_stats;
210*0dc2366fSVenugopal Iyer } total_stat_entry_t;
211*0dc2366fSVenugopal Iyer 
212*0dc2366fSVenugopal Iyer /*
213*0dc2366fSVenugopal Iyer  * Definitions for aggr stats
214*0dc2366fSVenugopal Iyer  */
215*0dc2366fSVenugopal Iyer typedef struct aggr_port_stat_s {
216*0dc2366fSVenugopal Iyer 	uint64_t	ap_ipackets;
217*0dc2366fSVenugopal Iyer 	uint64_t	ap_rbytes;
218*0dc2366fSVenugopal Iyer 	uint64_t	ap_opackets;
219*0dc2366fSVenugopal Iyer 	uint64_t	ap_obytes;
220*0dc2366fSVenugopal Iyer } aggr_port_stat_t;
221*0dc2366fSVenugopal Iyer 
222*0dc2366fSVenugopal Iyer typedef struct aggr_port_stat_entry_s {
223*0dc2366fSVenugopal Iyer 	datalink_id_t		ape_portlinkid;
224*0dc2366fSVenugopal Iyer 	aggr_port_stat_t	ape_stats;
225*0dc2366fSVenugopal Iyer } aggr_port_stat_entry_t;
226*0dc2366fSVenugopal Iyer 
227*0dc2366fSVenugopal Iyer /*
228*0dc2366fSVenugopal Iyer  * Definitions for query all stats
229*0dc2366fSVenugopal Iyer  */
230*0dc2366fSVenugopal Iyer typedef struct name_value_stat_s {
231*0dc2366fSVenugopal Iyer 	char				nv_statname[MAXSTATNAMELEN];
232*0dc2366fSVenugopal Iyer 	uint64_t			nv_statval;
233*0dc2366fSVenugopal Iyer 	struct name_value_stat_s	*nv_nextstat;
234*0dc2366fSVenugopal Iyer } name_value_stat_t;
235*0dc2366fSVenugopal Iyer 
236*0dc2366fSVenugopal Iyer typedef struct name_value_stat_entry_s {
237*0dc2366fSVenugopal Iyer 	char			nve_header[MAXSTATNAMELEN];
238*0dc2366fSVenugopal Iyer 	name_value_stat_t	*nve_stats;
239*0dc2366fSVenugopal Iyer } name_value_stat_entry_t;
240*0dc2366fSVenugopal Iyer 
241*0dc2366fSVenugopal Iyer /*
242*0dc2366fSVenugopal Iyer  * Definitions for flow stats
243*0dc2366fSVenugopal Iyer  */
244*0dc2366fSVenugopal Iyer typedef struct flow_stat_s {
245*0dc2366fSVenugopal Iyer 	uint64_t	fl_ipackets;
246*0dc2366fSVenugopal Iyer 	uint64_t	fl_rbytes;
247*0dc2366fSVenugopal Iyer 	uint64_t	fl_ierrors;
248*0dc2366fSVenugopal Iyer 	uint64_t	fl_opackets;
249*0dc2366fSVenugopal Iyer 	uint64_t	fl_obytes;
250*0dc2366fSVenugopal Iyer 	uint64_t	fl_oerrors;
251*0dc2366fSVenugopal Iyer 	uint64_t	fl_sdrops;
252*0dc2366fSVenugopal Iyer } flow_stat_t;
253*0dc2366fSVenugopal Iyer 
254da14cebeSEric Cheng typedef struct pktsum_s {
255da14cebeSEric Cheng 	hrtime_t	snaptime;
256da14cebeSEric Cheng 	uint64_t	ipackets;
257da14cebeSEric Cheng 	uint64_t	opackets;
258da14cebeSEric Cheng 	uint64_t	rbytes;
259da14cebeSEric Cheng 	uint64_t	obytes;
260da14cebeSEric Cheng 	uint64_t	ierrors;
261da14cebeSEric Cheng 	uint64_t	oerrors;
262da14cebeSEric Cheng } pktsum_t;
263da14cebeSEric Cheng 
2644ac67f02SAnurag S. Maskey extern void		dladm_continuous(dladm_handle_t, datalink_id_t,
2654ac67f02SAnurag S. Maskey 			    const char *, int, int);
266da14cebeSEric Cheng 
267da14cebeSEric Cheng extern kstat_t		*dladm_kstat_lookup(kstat_ctl_t *, const char *, int,
268da14cebeSEric Cheng 			    const char *, const char *);
269da14cebeSEric Cheng extern void		dladm_get_stats(kstat_ctl_t *, kstat_t *, pktsum_t *);
270da14cebeSEric Cheng extern int		dladm_kstat_value(kstat_t *, const char *, uint8_t,
271da14cebeSEric Cheng 			    void *);
2724ac67f02SAnurag S. Maskey extern dladm_status_t	dladm_get_single_mac_stat(dladm_handle_t, datalink_id_t,
2734ac67f02SAnurag S. Maskey 			    const char *, uint8_t, void *);
274da14cebeSEric Cheng 
275da14cebeSEric Cheng extern void		dladm_stats_total(pktsum_t *, pktsum_t *, pktsum_t *);
276da14cebeSEric Cheng extern void		dladm_stats_diff(pktsum_t *, pktsum_t *, pktsum_t *);
277da14cebeSEric Cheng 
278*0dc2366fSVenugopal Iyer extern dladm_stat_chain_t	*dladm_link_stat_query(dladm_handle_t,
279*0dc2366fSVenugopal Iyer 				    datalink_id_t, dladm_stat_type_t);
280*0dc2366fSVenugopal Iyer extern dladm_stat_chain_t	*dladm_link_stat_diffchain(dladm_stat_chain_t *,
281*0dc2366fSVenugopal Iyer 				    dladm_stat_chain_t *, dladm_stat_type_t);
282*0dc2366fSVenugopal Iyer extern dladm_stat_chain_t	*dladm_link_stat_query_all(dladm_handle_t,
283*0dc2366fSVenugopal Iyer 				    datalink_id_t, dladm_stat_type_t);
284*0dc2366fSVenugopal Iyer 
285*0dc2366fSVenugopal Iyer extern flow_stat_t		*dladm_flow_stat_query(const char *);
286*0dc2366fSVenugopal Iyer extern flow_stat_t		*dladm_flow_stat_diff(flow_stat_t *,
287*0dc2366fSVenugopal Iyer 				    flow_stat_t *);
288*0dc2366fSVenugopal Iyer extern name_value_stat_entry_t	*dladm_flow_stat_query_all(const char *);
289*0dc2366fSVenugopal Iyer 
290da14cebeSEric Cheng #ifdef	__cplusplus
291da14cebeSEric Cheng }
292da14cebeSEric Cheng #endif
293da14cebeSEric Cheng 
294da14cebeSEric Cheng #endif	/* _LIBDLSTAT_H */
295