xref: /illumos-gate/usr/src/lib/libdladm/common/libdlstat.h (revision 399dcf08ed1dc7e6abf8d7e5dc9447e11047c9f2)
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 /*
220dc2366fSVenugopal Iyer  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
23da14cebeSEric Cheng  * Use is subject to license terms.
24da14cebeSEric Cheng  */
25da14cebeSEric Cheng 
26*399dcf08Scarlos antonio neira bustos /*
27*399dcf08Scarlos antonio neira bustos  * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
28*399dcf08Scarlos antonio neira bustos  */
29*399dcf08Scarlos antonio neira bustos 
30da14cebeSEric Cheng #ifndef _LIBDLSTAT_H
31da14cebeSEric Cheng #define	_LIBDLSTAT_H
32da14cebeSEric Cheng 
33da14cebeSEric Cheng /*
34da14cebeSEric Cheng  * This file includes structures, macros and common routines shared by all
35da14cebeSEric Cheng  * data-link administration, and routines which are used to retrieve and
36da14cebeSEric Cheng  * display statistics.
37da14cebeSEric Cheng  */
38da14cebeSEric Cheng 
39da14cebeSEric Cheng #include <kstat.h>
40da14cebeSEric Cheng 
41da14cebeSEric Cheng #ifdef	__cplusplus
42da14cebeSEric Cheng extern "C" {
43da14cebeSEric Cheng #endif
44da14cebeSEric Cheng 
45da14cebeSEric Cheng #define	LINK_REPORT	1
46da14cebeSEric Cheng #define	FLOW_REPORT	2
47da14cebeSEric Cheng 
480dc2366fSVenugopal Iyer #define	DLSTAT_INVALID_ENTRY	-1
490dc2366fSVenugopal Iyer #define	MAXSTATNAMELEN	256
500dc2366fSVenugopal Iyer /*
510dc2366fSVenugopal Iyer  * Definitions common to all stats
520dc2366fSVenugopal Iyer  */
530dc2366fSVenugopal Iyer typedef struct dladm_stat_chain_s {
540dc2366fSVenugopal Iyer 	char				dc_statheader[MAXSTATNAMELEN];
550dc2366fSVenugopal Iyer 	void				*dc_statentry;
560dc2366fSVenugopal Iyer 	struct dladm_stat_chain_s	*dc_next;
570dc2366fSVenugopal Iyer } dladm_stat_chain_t;
580dc2366fSVenugopal Iyer 
590dc2366fSVenugopal Iyer typedef enum {
600dc2366fSVenugopal Iyer 	DLADM_STAT_RX_LANE = 0,		/* Per lane rx stats */
610dc2366fSVenugopal Iyer 	DLADM_STAT_TX_LANE,		/* Per lane tx stats */
620dc2366fSVenugopal Iyer 	DLADM_STAT_RX_LANE_TOTAL,	/* Stats summed across all rx lanes */
630dc2366fSVenugopal Iyer 	DLADM_STAT_TX_LANE_TOTAL,	/* Stats summed across all tx lanes */
640dc2366fSVenugopal Iyer 	DLADM_STAT_RX_LANE_FOUT,	/* Per fanout (rx lane) stats */
650dc2366fSVenugopal Iyer 	DLADM_STAT_RX_RING,		/* Per ring rx stats */
660dc2366fSVenugopal Iyer 	DLADM_STAT_TX_RING,		/* Per ring tx stats  */
670dc2366fSVenugopal Iyer 	DLADM_STAT_RX_RING_TOTAL,	/* Stats summed across all rx rings */
680dc2366fSVenugopal Iyer 	DLADM_STAT_TX_RING_TOTAL,	/* Stats summed across all tx rings */
690dc2366fSVenugopal Iyer 	DLADM_STAT_TOTAL,		/* Summary view */
700dc2366fSVenugopal Iyer 	DLADM_STAT_AGGR_PORT,		/* Aggr port stats */
710dc2366fSVenugopal Iyer 	DLADM_STAT_MISC,		/* Misc stats */
720dc2366fSVenugopal Iyer 	DLADM_STAT_NUM_STATS		/* This must always be the last entry */
730dc2366fSVenugopal Iyer } dladm_stat_type_t;
740dc2366fSVenugopal Iyer 
750dc2366fSVenugopal Iyer /*
760dc2366fSVenugopal Iyer  * Definitions for rx lane stats
770dc2366fSVenugopal Iyer  */
780dc2366fSVenugopal Iyer typedef struct rx_lane_stat_s {
790dc2366fSVenugopal Iyer 	uint64_t	rl_ipackets;
800dc2366fSVenugopal Iyer 	uint64_t	rl_rbytes;
810dc2366fSVenugopal Iyer 	uint64_t	rl_lclpackets;
820dc2366fSVenugopal Iyer 	uint64_t	rl_lclbytes;
830dc2366fSVenugopal Iyer 	uint64_t	rl_intrs;
840dc2366fSVenugopal Iyer 	uint64_t	rl_intrbytes;
850dc2366fSVenugopal Iyer 	uint64_t	rl_pollbytes;
860dc2366fSVenugopal Iyer 	uint64_t	rl_polls;
870dc2366fSVenugopal Iyer 	uint64_t	rl_sdrops;
880dc2366fSVenugopal Iyer 	uint64_t	rl_chl10;
890dc2366fSVenugopal Iyer 	uint64_t	rl_ch10_50;
900dc2366fSVenugopal Iyer 	uint64_t	rl_chg50;
910dc2366fSVenugopal Iyer } rx_lane_stat_t;
920dc2366fSVenugopal Iyer 
930dc2366fSVenugopal Iyer typedef enum {
940dc2366fSVenugopal Iyer 	L_HWLANE,
950dc2366fSVenugopal Iyer 	L_SWLANE,
960dc2366fSVenugopal Iyer 	L_LOCAL,
970dc2366fSVenugopal Iyer 	L_LCLSWLANE,
980dc2366fSVenugopal Iyer 	L_BCAST,
990dc2366fSVenugopal Iyer 	L_DFNCT
1000dc2366fSVenugopal Iyer } lane_type_t;
1010dc2366fSVenugopal Iyer 
1020dc2366fSVenugopal Iyer typedef struct rx_lane_stat_entry_s {
1030dc2366fSVenugopal Iyer 	int64_t		rle_index;
1040dc2366fSVenugopal Iyer 	lane_type_t	rle_id;
1050dc2366fSVenugopal Iyer 	rx_lane_stat_t	rle_stats;
1060dc2366fSVenugopal Iyer } rx_lane_stat_entry_t;
1070dc2366fSVenugopal Iyer 
1080dc2366fSVenugopal Iyer /*
1090dc2366fSVenugopal Iyer  * Definitions for tx lane stats
1100dc2366fSVenugopal Iyer  */
1110dc2366fSVenugopal Iyer typedef struct tx_lane_stat_s {
1120dc2366fSVenugopal Iyer 	uint64_t	tl_opackets;
1130dc2366fSVenugopal Iyer 	uint64_t	tl_obytes;
1140dc2366fSVenugopal Iyer 	uint64_t	tl_blockcnt;
1150dc2366fSVenugopal Iyer 	uint64_t	tl_unblockcnt;
1160dc2366fSVenugopal Iyer 	uint64_t	tl_sdrops;
1170dc2366fSVenugopal Iyer } tx_lane_stat_t;
1180dc2366fSVenugopal Iyer 
1190dc2366fSVenugopal Iyer typedef struct tx_lane_stat_entry_s {
1200dc2366fSVenugopal Iyer 	int64_t		tle_index;
1210dc2366fSVenugopal Iyer 	lane_type_t	tle_id;
1220dc2366fSVenugopal Iyer 	tx_lane_stat_t	tle_stats;
1230dc2366fSVenugopal Iyer } tx_lane_stat_entry_t;
1240dc2366fSVenugopal Iyer 
1250dc2366fSVenugopal Iyer /*
1260dc2366fSVenugopal Iyer  * Definitions for tx/rx misc stats
1270dc2366fSVenugopal Iyer  */
1280dc2366fSVenugopal Iyer typedef struct misc_stat_s {
1290dc2366fSVenugopal Iyer 	uint64_t	ms_multircv;
1300dc2366fSVenugopal Iyer 	uint64_t	ms_brdcstrcv;
1310dc2366fSVenugopal Iyer 	uint64_t	ms_multixmt;
1320dc2366fSVenugopal Iyer 	uint64_t	ms_brdcstxmt;
1330dc2366fSVenugopal Iyer 	uint64_t	ms_multircvbytes;
1340dc2366fSVenugopal Iyer 	uint64_t	ms_brdcstrcvbytes;
1350dc2366fSVenugopal Iyer 	uint64_t	ms_multixmtbytes;
1360dc2366fSVenugopal Iyer 	uint64_t	ms_brdcstxmtbytes;
1370dc2366fSVenugopal Iyer 	uint64_t	ms_txerrors;
1380dc2366fSVenugopal Iyer 	uint64_t	ms_macspoofed;
1390dc2366fSVenugopal Iyer 	uint64_t	ms_ipspoofed;
1400dc2366fSVenugopal Iyer 	uint64_t	ms_dhcpspoofed;
1410dc2366fSVenugopal Iyer 	uint64_t	ms_restricted;
1420dc2366fSVenugopal Iyer 	uint64_t	ms_dhcpdropped;
1430dc2366fSVenugopal Iyer 	uint64_t	ms_ipackets;
1440dc2366fSVenugopal Iyer 	uint64_t	ms_rbytes;
1450dc2366fSVenugopal Iyer 	uint64_t	ms_local;
1460dc2366fSVenugopal Iyer 	uint64_t	ms_localbytes;
1470dc2366fSVenugopal Iyer 	uint64_t	ms_intrs;
1480dc2366fSVenugopal Iyer 	uint64_t	ms_intrbytes;
1490dc2366fSVenugopal Iyer 	uint64_t	ms_polls;
1500dc2366fSVenugopal Iyer 	uint64_t	ms_pollbytes;
1510dc2366fSVenugopal Iyer 	uint64_t	ms_rxsdrops;
1520dc2366fSVenugopal Iyer 	uint64_t	ms_chainunder10;
1530dc2366fSVenugopal Iyer 	uint64_t	ms_chain10to50;
1540dc2366fSVenugopal Iyer 	uint64_t	ms_chainover50;
1550dc2366fSVenugopal Iyer 	uint64_t	ms_obytes;
1560dc2366fSVenugopal Iyer 	uint64_t	ms_opackets;
1570dc2366fSVenugopal Iyer 	uint64_t	ms_blockcnt;
1580dc2366fSVenugopal Iyer 	uint64_t	ms_unblockcnt;
1590dc2366fSVenugopal Iyer 	uint64_t	ms_txsdrops;
1600dc2366fSVenugopal Iyer } misc_stat_t;
1610dc2366fSVenugopal Iyer 
1620dc2366fSVenugopal Iyer /*
1630dc2366fSVenugopal Iyer  * To be consistent with other stat entries, misc stat
1640dc2366fSVenugopal Iyer  * is wrapped in stat entry
1650dc2366fSVenugopal Iyer  */
1660dc2366fSVenugopal Iyer typedef struct misc_stat_entry_s {
1670dc2366fSVenugopal Iyer 	misc_stat_t	mse_stats;
1680dc2366fSVenugopal Iyer } misc_stat_entry_t;
1690dc2366fSVenugopal Iyer 
1700dc2366fSVenugopal Iyer /*
1710dc2366fSVenugopal Iyer  * Definitions for ring stats: used by rx as well as tx
1720dc2366fSVenugopal Iyer  */
1730dc2366fSVenugopal Iyer typedef struct ring_stat_s {
1740dc2366fSVenugopal Iyer 	uint64_t	r_packets;
1750dc2366fSVenugopal Iyer 	uint64_t	r_bytes;
1760dc2366fSVenugopal Iyer } ring_stat_t;
1770dc2366fSVenugopal Iyer 
1780dc2366fSVenugopal Iyer typedef struct ring_stat_entry_s {
1790dc2366fSVenugopal Iyer 	int64_t		re_index;
1800dc2366fSVenugopal Iyer 	ring_stat_t	re_stats;
1810dc2366fSVenugopal Iyer } ring_stat_entry_t;
1820dc2366fSVenugopal Iyer 
1830dc2366fSVenugopal Iyer /*
1840dc2366fSVenugopal Iyer  * Definitions for fanout stats
1850dc2366fSVenugopal Iyer  */
1860dc2366fSVenugopal Iyer typedef struct fanout_stat_s {
1870dc2366fSVenugopal Iyer 	uint64_t	f_ipackets;
1880dc2366fSVenugopal Iyer 	uint64_t	f_rbytes;
1890dc2366fSVenugopal Iyer } fanout_stat_t;
1900dc2366fSVenugopal Iyer 
1910dc2366fSVenugopal Iyer typedef struct fanout_stat_entry_s {
1920dc2366fSVenugopal Iyer 	int64_t		fe_index;
1930dc2366fSVenugopal Iyer 	lane_type_t	fe_id;		/* hw, sw, local */
1940dc2366fSVenugopal Iyer 	int64_t		fe_foutindex;	/* fanout index */
1950dc2366fSVenugopal Iyer 	fanout_stat_t	fe_stats;
1960dc2366fSVenugopal Iyer } fanout_stat_entry_t;
1970dc2366fSVenugopal Iyer 
1980dc2366fSVenugopal Iyer /*
1990dc2366fSVenugopal Iyer  * Definitions for total stats
2000dc2366fSVenugopal Iyer  */
2010dc2366fSVenugopal Iyer typedef struct total_stat_s {
2020dc2366fSVenugopal Iyer 	uint64_t	ts_ipackets;
2030dc2366fSVenugopal Iyer 	uint64_t	ts_rbytes;
2040dc2366fSVenugopal Iyer 	uint64_t	ts_opackets;
2050dc2366fSVenugopal Iyer 	uint64_t	ts_obytes;
2060dc2366fSVenugopal Iyer } total_stat_t;
2070dc2366fSVenugopal Iyer 
2080dc2366fSVenugopal Iyer /*
2090dc2366fSVenugopal Iyer  * To be consistent with other stat entries, total stat
2100dc2366fSVenugopal Iyer  * is wrapped in stat entry
2110dc2366fSVenugopal Iyer  */
2120dc2366fSVenugopal Iyer typedef struct total_stat_entry_s {
2130dc2366fSVenugopal Iyer 	total_stat_t	tse_stats;
2140dc2366fSVenugopal Iyer } total_stat_entry_t;
2150dc2366fSVenugopal Iyer 
2160dc2366fSVenugopal Iyer /*
2170dc2366fSVenugopal Iyer  * Definitions for aggr stats
2180dc2366fSVenugopal Iyer  */
2190dc2366fSVenugopal Iyer typedef struct aggr_port_stat_s {
2200dc2366fSVenugopal Iyer 	uint64_t	ap_ipackets;
2210dc2366fSVenugopal Iyer 	uint64_t	ap_rbytes;
2220dc2366fSVenugopal Iyer 	uint64_t	ap_opackets;
2230dc2366fSVenugopal Iyer 	uint64_t	ap_obytes;
2240dc2366fSVenugopal Iyer } aggr_port_stat_t;
2250dc2366fSVenugopal Iyer 
2260dc2366fSVenugopal Iyer typedef struct aggr_port_stat_entry_s {
2270dc2366fSVenugopal Iyer 	datalink_id_t		ape_portlinkid;
2280dc2366fSVenugopal Iyer 	aggr_port_stat_t	ape_stats;
2290dc2366fSVenugopal Iyer } aggr_port_stat_entry_t;
2300dc2366fSVenugopal Iyer 
2310dc2366fSVenugopal Iyer /*
2320dc2366fSVenugopal Iyer  * Definitions for query all stats
2330dc2366fSVenugopal Iyer  */
2340dc2366fSVenugopal Iyer typedef struct name_value_stat_s {
2350dc2366fSVenugopal Iyer 	char				nv_statname[MAXSTATNAMELEN];
2360dc2366fSVenugopal Iyer 	uint64_t			nv_statval;
2370dc2366fSVenugopal Iyer 	struct name_value_stat_s	*nv_nextstat;
2380dc2366fSVenugopal Iyer } name_value_stat_t;
2390dc2366fSVenugopal Iyer 
2400dc2366fSVenugopal Iyer typedef struct name_value_stat_entry_s {
2410dc2366fSVenugopal Iyer 	char			nve_header[MAXSTATNAMELEN];
2420dc2366fSVenugopal Iyer 	name_value_stat_t	*nve_stats;
2430dc2366fSVenugopal Iyer } name_value_stat_entry_t;
2440dc2366fSVenugopal Iyer 
2450dc2366fSVenugopal Iyer /*
2460dc2366fSVenugopal Iyer  * Definitions for flow stats
2470dc2366fSVenugopal Iyer  */
2480dc2366fSVenugopal Iyer typedef struct flow_stat_s {
2490dc2366fSVenugopal Iyer 	uint64_t	fl_ipackets;
2500dc2366fSVenugopal Iyer 	uint64_t	fl_rbytes;
2510dc2366fSVenugopal Iyer 	uint64_t	fl_ierrors;
2520dc2366fSVenugopal Iyer 	uint64_t	fl_opackets;
2530dc2366fSVenugopal Iyer 	uint64_t	fl_obytes;
2540dc2366fSVenugopal Iyer 	uint64_t	fl_oerrors;
2550dc2366fSVenugopal Iyer 	uint64_t	fl_sdrops;
2560dc2366fSVenugopal Iyer } flow_stat_t;
2570dc2366fSVenugopal Iyer 
258da14cebeSEric Cheng typedef struct pktsum_s {
259da14cebeSEric Cheng 	hrtime_t	snaptime;
260da14cebeSEric Cheng 	uint64_t	ipackets;
261da14cebeSEric Cheng 	uint64_t	opackets;
262da14cebeSEric Cheng 	uint64_t	rbytes;
263da14cebeSEric Cheng 	uint64_t	obytes;
264da14cebeSEric Cheng 	uint64_t	ierrors;
265da14cebeSEric Cheng 	uint64_t	oerrors;
266da14cebeSEric Cheng } pktsum_t;
267da14cebeSEric Cheng 
268da14cebeSEric Cheng extern kstat_t		*dladm_kstat_lookup(kstat_ctl_t *, const char *, int,
269da14cebeSEric Cheng 			    const char *, const char *);
270da14cebeSEric Cheng extern void		dladm_get_stats(kstat_ctl_t *, kstat_t *, pktsum_t *);
271da14cebeSEric Cheng extern int		dladm_kstat_value(kstat_t *, const char *, uint8_t,
272da14cebeSEric Cheng 			    void *);
2734ac67f02SAnurag S. Maskey extern dladm_status_t	dladm_get_single_mac_stat(dladm_handle_t, datalink_id_t,
2744ac67f02SAnurag S. Maskey 			    const char *, uint8_t, void *);
275da14cebeSEric Cheng 
276da14cebeSEric Cheng extern void		dladm_stats_total(pktsum_t *, pktsum_t *, pktsum_t *);
277da14cebeSEric Cheng extern void		dladm_stats_diff(pktsum_t *, pktsum_t *, pktsum_t *);
278da14cebeSEric Cheng 
2790dc2366fSVenugopal Iyer extern dladm_stat_chain_t	*dladm_link_stat_query(dladm_handle_t,
2800dc2366fSVenugopal Iyer 				    datalink_id_t, dladm_stat_type_t);
2810dc2366fSVenugopal Iyer extern dladm_stat_chain_t	*dladm_link_stat_diffchain(dladm_stat_chain_t *,
2820dc2366fSVenugopal Iyer 				    dladm_stat_chain_t *, dladm_stat_type_t);
2830dc2366fSVenugopal Iyer extern dladm_stat_chain_t	*dladm_link_stat_query_all(dladm_handle_t,
2840dc2366fSVenugopal Iyer 				    datalink_id_t, dladm_stat_type_t);
2850dc2366fSVenugopal Iyer 
286*399dcf08Scarlos antonio neira bustos extern flow_stat_t		*dladm_flow_stat_query(dladm_handle_t,
287*399dcf08Scarlos antonio neira bustos 				    const char *);
2880dc2366fSVenugopal Iyer extern flow_stat_t		*dladm_flow_stat_diff(flow_stat_t *,
2890dc2366fSVenugopal Iyer 				    flow_stat_t *);
290*399dcf08Scarlos antonio neira bustos extern name_value_stat_entry_t	*dladm_flow_stat_query_all(dladm_handle_t,
291*399dcf08Scarlos antonio neira bustos 				    const char *);
2920dc2366fSVenugopal Iyer 
293da14cebeSEric Cheng #ifdef	__cplusplus
294da14cebeSEric Cheng }
295da14cebeSEric Cheng #endif
296da14cebeSEric Cheng 
297da14cebeSEric Cheng #endif	/* _LIBDLSTAT_H */
298