18275SEric Cheng /* 28275SEric Cheng * CDDL HEADER START 38275SEric Cheng * 48275SEric Cheng * The contents of this file are subject to the terms of the 58275SEric Cheng * Common Development and Distribution License (the "License"). 68275SEric Cheng * You may not use this file except in compliance with the License. 78275SEric Cheng * 88275SEric Cheng * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 98275SEric Cheng * or http://www.opensolaris.org/os/licensing. 108275SEric Cheng * See the License for the specific language governing permissions 118275SEric Cheng * and limitations under the License. 128275SEric Cheng * 138275SEric Cheng * When distributing Covered Code, include this CDDL HEADER in each 148275SEric Cheng * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 158275SEric Cheng * If applicable, add the following below this CDDL HEADER, with the 168275SEric Cheng * fields enclosed by brackets "[]" replaced with your own identifying 178275SEric Cheng * information: Portions Copyright [yyyy] [name of copyright owner] 188275SEric Cheng * 198275SEric Cheng * CDDL HEADER END 208275SEric Cheng */ 218275SEric Cheng /* 22*11878SVenu.Iyer@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 238275SEric Cheng * Use is subject to license terms. 248275SEric Cheng */ 258275SEric Cheng 268275SEric Cheng #ifndef _LIBDLSTAT_H 278275SEric Cheng #define _LIBDLSTAT_H 288275SEric Cheng 298275SEric Cheng /* 308275SEric Cheng * This file includes structures, macros and common routines shared by all 318275SEric Cheng * data-link administration, and routines which are used to retrieve and 328275SEric Cheng * display statistics. 338275SEric Cheng */ 348275SEric Cheng 358275SEric Cheng #include <kstat.h> 368275SEric Cheng 378275SEric Cheng #ifdef __cplusplus 388275SEric Cheng extern "C" { 398275SEric Cheng #endif 408275SEric Cheng 418275SEric Cheng #define LINK_REPORT 1 428275SEric Cheng #define FLOW_REPORT 2 438275SEric Cheng 44*11878SVenu.Iyer@Sun.COM #define DLSTAT_INVALID_ENTRY -1 45*11878SVenu.Iyer@Sun.COM #define MAXSTATNAMELEN 256 46*11878SVenu.Iyer@Sun.COM /* 47*11878SVenu.Iyer@Sun.COM * Definitions common to all stats 48*11878SVenu.Iyer@Sun.COM */ 49*11878SVenu.Iyer@Sun.COM typedef struct dladm_stat_chain_s { 50*11878SVenu.Iyer@Sun.COM char dc_statheader[MAXSTATNAMELEN]; 51*11878SVenu.Iyer@Sun.COM void *dc_statentry; 52*11878SVenu.Iyer@Sun.COM struct dladm_stat_chain_s *dc_next; 53*11878SVenu.Iyer@Sun.COM } dladm_stat_chain_t; 54*11878SVenu.Iyer@Sun.COM 55*11878SVenu.Iyer@Sun.COM typedef enum { 56*11878SVenu.Iyer@Sun.COM DLADM_STAT_RX_LANE = 0, /* Per lane rx stats */ 57*11878SVenu.Iyer@Sun.COM DLADM_STAT_TX_LANE, /* Per lane tx stats */ 58*11878SVenu.Iyer@Sun.COM DLADM_STAT_RX_LANE_TOTAL, /* Stats summed across all rx lanes */ 59*11878SVenu.Iyer@Sun.COM DLADM_STAT_TX_LANE_TOTAL, /* Stats summed across all tx lanes */ 60*11878SVenu.Iyer@Sun.COM DLADM_STAT_RX_LANE_FOUT, /* Per fanout (rx lane) stats */ 61*11878SVenu.Iyer@Sun.COM DLADM_STAT_RX_RING, /* Per ring rx stats */ 62*11878SVenu.Iyer@Sun.COM DLADM_STAT_TX_RING, /* Per ring tx stats */ 63*11878SVenu.Iyer@Sun.COM DLADM_STAT_RX_RING_TOTAL, /* Stats summed across all rx rings */ 64*11878SVenu.Iyer@Sun.COM DLADM_STAT_TX_RING_TOTAL, /* Stats summed across all tx rings */ 65*11878SVenu.Iyer@Sun.COM DLADM_STAT_TOTAL, /* Summary view */ 66*11878SVenu.Iyer@Sun.COM DLADM_STAT_AGGR_PORT, /* Aggr port stats */ 67*11878SVenu.Iyer@Sun.COM DLADM_STAT_MISC, /* Misc stats */ 68*11878SVenu.Iyer@Sun.COM DLADM_STAT_NUM_STATS /* This must always be the last entry */ 69*11878SVenu.Iyer@Sun.COM } dladm_stat_type_t; 70*11878SVenu.Iyer@Sun.COM 71*11878SVenu.Iyer@Sun.COM /* 72*11878SVenu.Iyer@Sun.COM * Definitions for rx lane stats 73*11878SVenu.Iyer@Sun.COM */ 74*11878SVenu.Iyer@Sun.COM typedef struct rx_lane_stat_s { 75*11878SVenu.Iyer@Sun.COM uint64_t rl_ipackets; 76*11878SVenu.Iyer@Sun.COM uint64_t rl_rbytes; 77*11878SVenu.Iyer@Sun.COM uint64_t rl_lclpackets; 78*11878SVenu.Iyer@Sun.COM uint64_t rl_lclbytes; 79*11878SVenu.Iyer@Sun.COM uint64_t rl_intrs; 80*11878SVenu.Iyer@Sun.COM uint64_t rl_intrbytes; 81*11878SVenu.Iyer@Sun.COM uint64_t rl_pollbytes; 82*11878SVenu.Iyer@Sun.COM uint64_t rl_polls; 83*11878SVenu.Iyer@Sun.COM uint64_t rl_sdrops; 84*11878SVenu.Iyer@Sun.COM uint64_t rl_chl10; 85*11878SVenu.Iyer@Sun.COM uint64_t rl_ch10_50; 86*11878SVenu.Iyer@Sun.COM uint64_t rl_chg50; 87*11878SVenu.Iyer@Sun.COM } rx_lane_stat_t; 88*11878SVenu.Iyer@Sun.COM 89*11878SVenu.Iyer@Sun.COM typedef enum { 90*11878SVenu.Iyer@Sun.COM L_HWLANE, 91*11878SVenu.Iyer@Sun.COM L_SWLANE, 92*11878SVenu.Iyer@Sun.COM L_LOCAL, 93*11878SVenu.Iyer@Sun.COM L_LCLSWLANE, 94*11878SVenu.Iyer@Sun.COM L_BCAST, 95*11878SVenu.Iyer@Sun.COM L_DFNCT 96*11878SVenu.Iyer@Sun.COM } lane_type_t; 97*11878SVenu.Iyer@Sun.COM 98*11878SVenu.Iyer@Sun.COM typedef struct rx_lane_stat_entry_s { 99*11878SVenu.Iyer@Sun.COM int64_t rle_index; 100*11878SVenu.Iyer@Sun.COM lane_type_t rle_id; 101*11878SVenu.Iyer@Sun.COM rx_lane_stat_t rle_stats; 102*11878SVenu.Iyer@Sun.COM } rx_lane_stat_entry_t; 103*11878SVenu.Iyer@Sun.COM 104*11878SVenu.Iyer@Sun.COM /* 105*11878SVenu.Iyer@Sun.COM * Definitions for tx lane stats 106*11878SVenu.Iyer@Sun.COM */ 107*11878SVenu.Iyer@Sun.COM typedef struct tx_lane_stat_s { 108*11878SVenu.Iyer@Sun.COM uint64_t tl_opackets; 109*11878SVenu.Iyer@Sun.COM uint64_t tl_obytes; 110*11878SVenu.Iyer@Sun.COM uint64_t tl_blockcnt; 111*11878SVenu.Iyer@Sun.COM uint64_t tl_unblockcnt; 112*11878SVenu.Iyer@Sun.COM uint64_t tl_sdrops; 113*11878SVenu.Iyer@Sun.COM } tx_lane_stat_t; 114*11878SVenu.Iyer@Sun.COM 115*11878SVenu.Iyer@Sun.COM typedef struct tx_lane_stat_entry_s { 116*11878SVenu.Iyer@Sun.COM int64_t tle_index; 117*11878SVenu.Iyer@Sun.COM lane_type_t tle_id; 118*11878SVenu.Iyer@Sun.COM tx_lane_stat_t tle_stats; 119*11878SVenu.Iyer@Sun.COM } tx_lane_stat_entry_t; 120*11878SVenu.Iyer@Sun.COM 121*11878SVenu.Iyer@Sun.COM /* 122*11878SVenu.Iyer@Sun.COM * Definitions for tx/rx misc stats 123*11878SVenu.Iyer@Sun.COM */ 124*11878SVenu.Iyer@Sun.COM typedef struct misc_stat_s { 125*11878SVenu.Iyer@Sun.COM uint64_t ms_multircv; 126*11878SVenu.Iyer@Sun.COM uint64_t ms_brdcstrcv; 127*11878SVenu.Iyer@Sun.COM uint64_t ms_multixmt; 128*11878SVenu.Iyer@Sun.COM uint64_t ms_brdcstxmt; 129*11878SVenu.Iyer@Sun.COM uint64_t ms_multircvbytes; 130*11878SVenu.Iyer@Sun.COM uint64_t ms_brdcstrcvbytes; 131*11878SVenu.Iyer@Sun.COM uint64_t ms_multixmtbytes; 132*11878SVenu.Iyer@Sun.COM uint64_t ms_brdcstxmtbytes; 133*11878SVenu.Iyer@Sun.COM uint64_t ms_txerrors; 134*11878SVenu.Iyer@Sun.COM uint64_t ms_macspoofed; 135*11878SVenu.Iyer@Sun.COM uint64_t ms_ipspoofed; 136*11878SVenu.Iyer@Sun.COM uint64_t ms_dhcpspoofed; 137*11878SVenu.Iyer@Sun.COM uint64_t ms_restricted; 138*11878SVenu.Iyer@Sun.COM uint64_t ms_dhcpdropped; 139*11878SVenu.Iyer@Sun.COM uint64_t ms_ipackets; 140*11878SVenu.Iyer@Sun.COM uint64_t ms_rbytes; 141*11878SVenu.Iyer@Sun.COM uint64_t ms_local; 142*11878SVenu.Iyer@Sun.COM uint64_t ms_localbytes; 143*11878SVenu.Iyer@Sun.COM uint64_t ms_intrs; 144*11878SVenu.Iyer@Sun.COM uint64_t ms_intrbytes; 145*11878SVenu.Iyer@Sun.COM uint64_t ms_polls; 146*11878SVenu.Iyer@Sun.COM uint64_t ms_pollbytes; 147*11878SVenu.Iyer@Sun.COM uint64_t ms_rxsdrops; 148*11878SVenu.Iyer@Sun.COM uint64_t ms_chainunder10; 149*11878SVenu.Iyer@Sun.COM uint64_t ms_chain10to50; 150*11878SVenu.Iyer@Sun.COM uint64_t ms_chainover50; 151*11878SVenu.Iyer@Sun.COM uint64_t ms_obytes; 152*11878SVenu.Iyer@Sun.COM uint64_t ms_opackets; 153*11878SVenu.Iyer@Sun.COM uint64_t ms_blockcnt; 154*11878SVenu.Iyer@Sun.COM uint64_t ms_unblockcnt; 155*11878SVenu.Iyer@Sun.COM uint64_t ms_txsdrops; 156*11878SVenu.Iyer@Sun.COM } misc_stat_t; 157*11878SVenu.Iyer@Sun.COM 158*11878SVenu.Iyer@Sun.COM /* 159*11878SVenu.Iyer@Sun.COM * To be consistent with other stat entries, misc stat 160*11878SVenu.Iyer@Sun.COM * is wrapped in stat entry 161*11878SVenu.Iyer@Sun.COM */ 162*11878SVenu.Iyer@Sun.COM typedef struct misc_stat_entry_s { 163*11878SVenu.Iyer@Sun.COM misc_stat_t mse_stats; 164*11878SVenu.Iyer@Sun.COM } misc_stat_entry_t; 165*11878SVenu.Iyer@Sun.COM 166*11878SVenu.Iyer@Sun.COM /* 167*11878SVenu.Iyer@Sun.COM * Definitions for ring stats: used by rx as well as tx 168*11878SVenu.Iyer@Sun.COM */ 169*11878SVenu.Iyer@Sun.COM typedef struct ring_stat_s { 170*11878SVenu.Iyer@Sun.COM uint64_t r_packets; 171*11878SVenu.Iyer@Sun.COM uint64_t r_bytes; 172*11878SVenu.Iyer@Sun.COM } ring_stat_t; 173*11878SVenu.Iyer@Sun.COM 174*11878SVenu.Iyer@Sun.COM typedef struct ring_stat_entry_s { 175*11878SVenu.Iyer@Sun.COM int64_t re_index; 176*11878SVenu.Iyer@Sun.COM ring_stat_t re_stats; 177*11878SVenu.Iyer@Sun.COM } ring_stat_entry_t; 178*11878SVenu.Iyer@Sun.COM 179*11878SVenu.Iyer@Sun.COM /* 180*11878SVenu.Iyer@Sun.COM * Definitions for fanout stats 181*11878SVenu.Iyer@Sun.COM */ 182*11878SVenu.Iyer@Sun.COM typedef struct fanout_stat_s { 183*11878SVenu.Iyer@Sun.COM uint64_t f_ipackets; 184*11878SVenu.Iyer@Sun.COM uint64_t f_rbytes; 185*11878SVenu.Iyer@Sun.COM } fanout_stat_t; 186*11878SVenu.Iyer@Sun.COM 187*11878SVenu.Iyer@Sun.COM typedef struct fanout_stat_entry_s { 188*11878SVenu.Iyer@Sun.COM int64_t fe_index; 189*11878SVenu.Iyer@Sun.COM lane_type_t fe_id; /* hw, sw, local */ 190*11878SVenu.Iyer@Sun.COM int64_t fe_foutindex; /* fanout index */ 191*11878SVenu.Iyer@Sun.COM fanout_stat_t fe_stats; 192*11878SVenu.Iyer@Sun.COM } fanout_stat_entry_t; 193*11878SVenu.Iyer@Sun.COM 194*11878SVenu.Iyer@Sun.COM /* 195*11878SVenu.Iyer@Sun.COM * Definitions for total stats 196*11878SVenu.Iyer@Sun.COM */ 197*11878SVenu.Iyer@Sun.COM typedef struct total_stat_s { 198*11878SVenu.Iyer@Sun.COM uint64_t ts_ipackets; 199*11878SVenu.Iyer@Sun.COM uint64_t ts_rbytes; 200*11878SVenu.Iyer@Sun.COM uint64_t ts_opackets; 201*11878SVenu.Iyer@Sun.COM uint64_t ts_obytes; 202*11878SVenu.Iyer@Sun.COM } total_stat_t; 203*11878SVenu.Iyer@Sun.COM 204*11878SVenu.Iyer@Sun.COM /* 205*11878SVenu.Iyer@Sun.COM * To be consistent with other stat entries, total stat 206*11878SVenu.Iyer@Sun.COM * is wrapped in stat entry 207*11878SVenu.Iyer@Sun.COM */ 208*11878SVenu.Iyer@Sun.COM typedef struct total_stat_entry_s { 209*11878SVenu.Iyer@Sun.COM total_stat_t tse_stats; 210*11878SVenu.Iyer@Sun.COM } total_stat_entry_t; 211*11878SVenu.Iyer@Sun.COM 212*11878SVenu.Iyer@Sun.COM /* 213*11878SVenu.Iyer@Sun.COM * Definitions for aggr stats 214*11878SVenu.Iyer@Sun.COM */ 215*11878SVenu.Iyer@Sun.COM typedef struct aggr_port_stat_s { 216*11878SVenu.Iyer@Sun.COM uint64_t ap_ipackets; 217*11878SVenu.Iyer@Sun.COM uint64_t ap_rbytes; 218*11878SVenu.Iyer@Sun.COM uint64_t ap_opackets; 219*11878SVenu.Iyer@Sun.COM uint64_t ap_obytes; 220*11878SVenu.Iyer@Sun.COM } aggr_port_stat_t; 221*11878SVenu.Iyer@Sun.COM 222*11878SVenu.Iyer@Sun.COM typedef struct aggr_port_stat_entry_s { 223*11878SVenu.Iyer@Sun.COM datalink_id_t ape_portlinkid; 224*11878SVenu.Iyer@Sun.COM aggr_port_stat_t ape_stats; 225*11878SVenu.Iyer@Sun.COM } aggr_port_stat_entry_t; 226*11878SVenu.Iyer@Sun.COM 227*11878SVenu.Iyer@Sun.COM /* 228*11878SVenu.Iyer@Sun.COM * Definitions for query all stats 229*11878SVenu.Iyer@Sun.COM */ 230*11878SVenu.Iyer@Sun.COM typedef struct name_value_stat_s { 231*11878SVenu.Iyer@Sun.COM char nv_statname[MAXSTATNAMELEN]; 232*11878SVenu.Iyer@Sun.COM uint64_t nv_statval; 233*11878SVenu.Iyer@Sun.COM struct name_value_stat_s *nv_nextstat; 234*11878SVenu.Iyer@Sun.COM } name_value_stat_t; 235*11878SVenu.Iyer@Sun.COM 236*11878SVenu.Iyer@Sun.COM typedef struct name_value_stat_entry_s { 237*11878SVenu.Iyer@Sun.COM char nve_header[MAXSTATNAMELEN]; 238*11878SVenu.Iyer@Sun.COM name_value_stat_t *nve_stats; 239*11878SVenu.Iyer@Sun.COM } name_value_stat_entry_t; 240*11878SVenu.Iyer@Sun.COM 241*11878SVenu.Iyer@Sun.COM /* 242*11878SVenu.Iyer@Sun.COM * Definitions for flow stats 243*11878SVenu.Iyer@Sun.COM */ 244*11878SVenu.Iyer@Sun.COM typedef struct flow_stat_s { 245*11878SVenu.Iyer@Sun.COM uint64_t fl_ipackets; 246*11878SVenu.Iyer@Sun.COM uint64_t fl_rbytes; 247*11878SVenu.Iyer@Sun.COM uint64_t fl_ierrors; 248*11878SVenu.Iyer@Sun.COM uint64_t fl_opackets; 249*11878SVenu.Iyer@Sun.COM uint64_t fl_obytes; 250*11878SVenu.Iyer@Sun.COM uint64_t fl_oerrors; 251*11878SVenu.Iyer@Sun.COM uint64_t fl_sdrops; 252*11878SVenu.Iyer@Sun.COM } flow_stat_t; 253*11878SVenu.Iyer@Sun.COM 2548275SEric Cheng typedef struct pktsum_s { 2558275SEric Cheng hrtime_t snaptime; 2568275SEric Cheng uint64_t ipackets; 2578275SEric Cheng uint64_t opackets; 2588275SEric Cheng uint64_t rbytes; 2598275SEric Cheng uint64_t obytes; 2608275SEric Cheng uint64_t ierrors; 2618275SEric Cheng uint64_t oerrors; 2628275SEric Cheng } pktsum_t; 2638275SEric Cheng 2648453SAnurag.Maskey@Sun.COM extern void dladm_continuous(dladm_handle_t, datalink_id_t, 2658453SAnurag.Maskey@Sun.COM const char *, int, int); 2668275SEric Cheng 2678275SEric Cheng extern kstat_t *dladm_kstat_lookup(kstat_ctl_t *, const char *, int, 2688275SEric Cheng const char *, const char *); 2698275SEric Cheng extern void dladm_get_stats(kstat_ctl_t *, kstat_t *, pktsum_t *); 2708275SEric Cheng extern int dladm_kstat_value(kstat_t *, const char *, uint8_t, 2718275SEric Cheng void *); 2728453SAnurag.Maskey@Sun.COM extern dladm_status_t dladm_get_single_mac_stat(dladm_handle_t, datalink_id_t, 2738453SAnurag.Maskey@Sun.COM const char *, uint8_t, void *); 2748275SEric Cheng 2758275SEric Cheng extern void dladm_stats_total(pktsum_t *, pktsum_t *, pktsum_t *); 2768275SEric Cheng extern void dladm_stats_diff(pktsum_t *, pktsum_t *, pktsum_t *); 2778275SEric Cheng 278*11878SVenu.Iyer@Sun.COM extern dladm_stat_chain_t *dladm_link_stat_query(dladm_handle_t, 279*11878SVenu.Iyer@Sun.COM datalink_id_t, dladm_stat_type_t); 280*11878SVenu.Iyer@Sun.COM extern dladm_stat_chain_t *dladm_link_stat_diffchain(dladm_stat_chain_t *, 281*11878SVenu.Iyer@Sun.COM dladm_stat_chain_t *, dladm_stat_type_t); 282*11878SVenu.Iyer@Sun.COM extern dladm_stat_chain_t *dladm_link_stat_query_all(dladm_handle_t, 283*11878SVenu.Iyer@Sun.COM datalink_id_t, dladm_stat_type_t); 284*11878SVenu.Iyer@Sun.COM 285*11878SVenu.Iyer@Sun.COM extern flow_stat_t *dladm_flow_stat_query(const char *); 286*11878SVenu.Iyer@Sun.COM extern flow_stat_t *dladm_flow_stat_diff(flow_stat_t *, 287*11878SVenu.Iyer@Sun.COM flow_stat_t *); 288*11878SVenu.Iyer@Sun.COM extern name_value_stat_entry_t *dladm_flow_stat_query_all(const char *); 289*11878SVenu.Iyer@Sun.COM 2908275SEric Cheng #ifdef __cplusplus 2918275SEric Cheng } 2928275SEric Cheng #endif 2938275SEric Cheng 2948275SEric Cheng #endif /* _LIBDLSTAT_H */ 295