1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate /* 30*7c478bd9Sstevel@tonic-gate * MAC Services Module 31*7c478bd9Sstevel@tonic-gate */ 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/stream.h> 36*7c478bd9Sstevel@tonic-gate #include <sys/kstat.h> 37*7c478bd9Sstevel@tonic-gate #include <sys/mac.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/mac_impl.h> 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate typedef struct i_mac_stat_info_s { 41*7c478bd9Sstevel@tonic-gate enum mac_stat msi_stat; 42*7c478bd9Sstevel@tonic-gate char *msi_name; 43*7c478bd9Sstevel@tonic-gate uint_t msi_type; 44*7c478bd9Sstevel@tonic-gate } i_mac_stat_info_t; 45*7c478bd9Sstevel@tonic-gate 46*7c478bd9Sstevel@tonic-gate static i_mac_stat_info_t i_mac_si[] = { 47*7c478bd9Sstevel@tonic-gate { MAC_STAT_IFSPEED, "ifspeed", KSTAT_DATA_UINT64 }, 48*7c478bd9Sstevel@tonic-gate { MAC_STAT_MULTIRCV, "multircv", KSTAT_DATA_UINT32 }, 49*7c478bd9Sstevel@tonic-gate { MAC_STAT_BRDCSTRCV, "brdcstrcv", KSTAT_DATA_UINT32 }, 50*7c478bd9Sstevel@tonic-gate { MAC_STAT_MULTIXMT, "multixmt", KSTAT_DATA_UINT32 }, 51*7c478bd9Sstevel@tonic-gate { MAC_STAT_BRDCSTXMT, "brdcstxmt", KSTAT_DATA_UINT32 }, 52*7c478bd9Sstevel@tonic-gate { MAC_STAT_NORCVBUF, "norcvbuf", KSTAT_DATA_UINT32 }, 53*7c478bd9Sstevel@tonic-gate { MAC_STAT_IERRORS, "ierrors", KSTAT_DATA_UINT32 }, 54*7c478bd9Sstevel@tonic-gate { MAC_STAT_UNKNOWNS, "unknowns", KSTAT_DATA_UINT32 }, 55*7c478bd9Sstevel@tonic-gate { MAC_STAT_NOXMTBUF, "noxmtbuf", KSTAT_DATA_UINT32 }, 56*7c478bd9Sstevel@tonic-gate { MAC_STAT_OERRORS, "oerrors", KSTAT_DATA_UINT32 }, 57*7c478bd9Sstevel@tonic-gate { MAC_STAT_COLLISIONS, "collisions", KSTAT_DATA_UINT32 }, 58*7c478bd9Sstevel@tonic-gate { MAC_STAT_RBYTES, "rbytes", KSTAT_DATA_UINT32 }, 59*7c478bd9Sstevel@tonic-gate { MAC_STAT_IPACKETS, "ipackets", KSTAT_DATA_UINT32 }, 60*7c478bd9Sstevel@tonic-gate { MAC_STAT_OBYTES, "obytes", KSTAT_DATA_UINT32 }, 61*7c478bd9Sstevel@tonic-gate { MAC_STAT_OPACKETS, "opackets", KSTAT_DATA_UINT32 }, 62*7c478bd9Sstevel@tonic-gate { MAC_STAT_RBYTES, "rbytes64", KSTAT_DATA_UINT64 }, 63*7c478bd9Sstevel@tonic-gate { MAC_STAT_IPACKETS, "ipackets64", KSTAT_DATA_UINT64 }, 64*7c478bd9Sstevel@tonic-gate { MAC_STAT_OBYTES, "obytes64", KSTAT_DATA_UINT64 }, 65*7c478bd9Sstevel@tonic-gate { MAC_STAT_OPACKETS, "opackets64", KSTAT_DATA_UINT64 }, 66*7c478bd9Sstevel@tonic-gate { MAC_STAT_ALIGN_ERRORS, "align_errors", KSTAT_DATA_UINT32 }, 67*7c478bd9Sstevel@tonic-gate { MAC_STAT_FCS_ERRORS, "fcs_errors", KSTAT_DATA_UINT32 }, 68*7c478bd9Sstevel@tonic-gate { MAC_STAT_FIRST_COLLISIONS, "first_collsions", KSTAT_DATA_UINT32 }, 69*7c478bd9Sstevel@tonic-gate { MAC_STAT_MULTI_COLLISIONS, "multi_collsions", KSTAT_DATA_UINT32 }, 70*7c478bd9Sstevel@tonic-gate { MAC_STAT_SQE_ERRORS, "sqe_errors", KSTAT_DATA_UINT32 }, 71*7c478bd9Sstevel@tonic-gate { MAC_STAT_DEFER_XMTS, "defer_xmts", KSTAT_DATA_UINT32 }, 72*7c478bd9Sstevel@tonic-gate { MAC_STAT_TX_LATE_COLLISIONS, "tx_late_collsions", KSTAT_DATA_UINT32 }, 73*7c478bd9Sstevel@tonic-gate { MAC_STAT_EX_COLLISIONS, "ex_collsions", KSTAT_DATA_UINT32 }, 74*7c478bd9Sstevel@tonic-gate { MAC_STAT_MACXMT_ERRORS, "macxmt_errors", KSTAT_DATA_UINT32 }, 75*7c478bd9Sstevel@tonic-gate { MAC_STAT_CARRIER_ERRORS, "carrier_errors", KSTAT_DATA_UINT32 }, 76*7c478bd9Sstevel@tonic-gate { MAC_STAT_TOOLONG_ERRORS, "toolong_errors", KSTAT_DATA_UINT32 }, 77*7c478bd9Sstevel@tonic-gate { MAC_STAT_MACRCV_ERRORS, "macrcv_errors", KSTAT_DATA_UINT32 }, 78*7c478bd9Sstevel@tonic-gate { MAC_STAT_XCVR_ADDR, "xcvr_addr", KSTAT_DATA_UINT32 }, 79*7c478bd9Sstevel@tonic-gate { MAC_STAT_XCVR_ID, "xcvr_id", KSTAT_DATA_UINT32 }, 80*7c478bd9Sstevel@tonic-gate { MAC_STAT_XCVR_INUSE, "xcvr_inuse", KSTAT_DATA_UINT32 }, 81*7c478bd9Sstevel@tonic-gate { MAC_STAT_CAP_1000FDX, "cap_1000fdx", KSTAT_DATA_UINT32 }, 82*7c478bd9Sstevel@tonic-gate { MAC_STAT_CAP_1000HDX, "cap_1000hdx", KSTAT_DATA_UINT32 }, 83*7c478bd9Sstevel@tonic-gate { MAC_STAT_CAP_100FDX, "cap_100fdx", KSTAT_DATA_UINT32 }, 84*7c478bd9Sstevel@tonic-gate { MAC_STAT_CAP_100HDX, "cap_100hdx", KSTAT_DATA_UINT32 }, 85*7c478bd9Sstevel@tonic-gate { MAC_STAT_CAP_10FDX, "cap_10fdx", KSTAT_DATA_UINT32 }, 86*7c478bd9Sstevel@tonic-gate { MAC_STAT_CAP_10HDX, "cap_10hdx", KSTAT_DATA_UINT32 }, 87*7c478bd9Sstevel@tonic-gate { MAC_STAT_CAP_ASMPAUSE, "cap_asmpause", KSTAT_DATA_UINT32 }, 88*7c478bd9Sstevel@tonic-gate { MAC_STAT_CAP_PAUSE, "cap_pause", KSTAT_DATA_UINT32 }, 89*7c478bd9Sstevel@tonic-gate { MAC_STAT_CAP_AUTONEG, "cap_autoneg", KSTAT_DATA_UINT32 }, 90*7c478bd9Sstevel@tonic-gate { MAC_STAT_ADV_CAP_1000FDX, "adv_cap_1000fdx", KSTAT_DATA_UINT32 }, 91*7c478bd9Sstevel@tonic-gate { MAC_STAT_ADV_CAP_1000HDX, "adv_cap_1000hdx", KSTAT_DATA_UINT32 }, 92*7c478bd9Sstevel@tonic-gate { MAC_STAT_ADV_CAP_100FDX, "adv_cap_100fdx", KSTAT_DATA_UINT32 }, 93*7c478bd9Sstevel@tonic-gate { MAC_STAT_ADV_CAP_100HDX, "adv_cap_100hdx", KSTAT_DATA_UINT32 }, 94*7c478bd9Sstevel@tonic-gate { MAC_STAT_ADV_CAP_10FDX, "adv_cap_10fdx", KSTAT_DATA_UINT32 }, 95*7c478bd9Sstevel@tonic-gate { MAC_STAT_ADV_CAP_10HDX, "adv_cap_10hdx", KSTAT_DATA_UINT32 }, 96*7c478bd9Sstevel@tonic-gate { MAC_STAT_ADV_CAP_ASMPAUSE, "adv_cap_asmpause", KSTAT_DATA_UINT32 }, 97*7c478bd9Sstevel@tonic-gate { MAC_STAT_ADV_CAP_PAUSE, "adv_cap_pause", KSTAT_DATA_UINT32 }, 98*7c478bd9Sstevel@tonic-gate { MAC_STAT_ADV_CAP_AUTONEG, "adv_cap_autoneg", KSTAT_DATA_UINT32 }, 99*7c478bd9Sstevel@tonic-gate { MAC_STAT_LP_CAP_1000FDX, "lp_cap_1000fdx", KSTAT_DATA_UINT32 }, 100*7c478bd9Sstevel@tonic-gate { MAC_STAT_LP_CAP_1000HDX, "lp_cap_1000hdx", KSTAT_DATA_UINT32 }, 101*7c478bd9Sstevel@tonic-gate { MAC_STAT_LP_CAP_100FDX, "lp_cap_100fdx", KSTAT_DATA_UINT32 }, 102*7c478bd9Sstevel@tonic-gate { MAC_STAT_LP_CAP_100HDX, "lp_cap_100hdx", KSTAT_DATA_UINT32 }, 103*7c478bd9Sstevel@tonic-gate { MAC_STAT_LP_CAP_10FDX, "lp_cap_10fdx", KSTAT_DATA_UINT32 }, 104*7c478bd9Sstevel@tonic-gate { MAC_STAT_LP_CAP_10HDX, "lp_cap_10hdx", KSTAT_DATA_UINT32 }, 105*7c478bd9Sstevel@tonic-gate { MAC_STAT_LP_CAP_ASMPAUSE, "lp_cap_asmpause", KSTAT_DATA_UINT32 }, 106*7c478bd9Sstevel@tonic-gate { MAC_STAT_LP_CAP_PAUSE, "lp_cap_pause", KSTAT_DATA_UINT32 }, 107*7c478bd9Sstevel@tonic-gate { MAC_STAT_LP_CAP_AUTONEG, "lp_cap_autoneg", KSTAT_DATA_UINT32 }, 108*7c478bd9Sstevel@tonic-gate { MAC_STAT_LINK_ASMPAUSE, "link_asmpause", KSTAT_DATA_UINT32 }, 109*7c478bd9Sstevel@tonic-gate { MAC_STAT_LINK_PAUSE, "link_pause", KSTAT_DATA_UINT32 }, 110*7c478bd9Sstevel@tonic-gate { MAC_STAT_LINK_AUTONEG, "link_autoneg", KSTAT_DATA_UINT32 }, 111*7c478bd9Sstevel@tonic-gate { MAC_STAT_LINK_DUPLEX, "link_duplex", KSTAT_DATA_UINT32 } 112*7c478bd9Sstevel@tonic-gate }; 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate #define STAT_INFO_COUNT (sizeof (i_mac_si) / sizeof (i_mac_si[0])) 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate /* 117*7c478bd9Sstevel@tonic-gate * Private functions. 118*7c478bd9Sstevel@tonic-gate */ 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate static int 121*7c478bd9Sstevel@tonic-gate i_mac_stat_update(kstat_t *ksp, int rw) 122*7c478bd9Sstevel@tonic-gate { 123*7c478bd9Sstevel@tonic-gate mac_impl_t *mip = ksp->ks_private; 124*7c478bd9Sstevel@tonic-gate mac_t *mp = mip->mi_mp; 125*7c478bd9Sstevel@tonic-gate kstat_named_t *knp; 126*7c478bd9Sstevel@tonic-gate uint_t i; 127*7c478bd9Sstevel@tonic-gate uint64_t val; 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate if (rw != KSTAT_READ) 130*7c478bd9Sstevel@tonic-gate return (EACCES); 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate knp = ksp->ks_data; 133*7c478bd9Sstevel@tonic-gate for (i = 0; i < STAT_INFO_COUNT; i++) { 134*7c478bd9Sstevel@tonic-gate if (!(mp->m_info.mi_stat[i_mac_si[i].msi_stat])) 135*7c478bd9Sstevel@tonic-gate continue; 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate val = mac_stat_get((mac_handle_t)mip, i_mac_si[i].msi_stat); 138*7c478bd9Sstevel@tonic-gate 139*7c478bd9Sstevel@tonic-gate switch (i_mac_si[i].msi_type) { 140*7c478bd9Sstevel@tonic-gate case KSTAT_DATA_UINT64: 141*7c478bd9Sstevel@tonic-gate knp->value.ui64 = val; 142*7c478bd9Sstevel@tonic-gate break; 143*7c478bd9Sstevel@tonic-gate case KSTAT_DATA_UINT32: 144*7c478bd9Sstevel@tonic-gate knp->value.ui32 = (uint32_t)val; 145*7c478bd9Sstevel@tonic-gate break; 146*7c478bd9Sstevel@tonic-gate default: 147*7c478bd9Sstevel@tonic-gate ASSERT(B_FALSE); 148*7c478bd9Sstevel@tonic-gate break; 149*7c478bd9Sstevel@tonic-gate } 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate knp++; 152*7c478bd9Sstevel@tonic-gate } 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate (knp++)->value.ui32 = mip->mi_link; 155*7c478bd9Sstevel@tonic-gate (knp++)->value.ui32 = (mip->mi_link == LINK_STATE_UP); 156*7c478bd9Sstevel@tonic-gate knp->value.ui32 = (mip->mi_devpromisc != 0); 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate return (0); 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate 161*7c478bd9Sstevel@tonic-gate /* 162*7c478bd9Sstevel@tonic-gate * Exported functions. 163*7c478bd9Sstevel@tonic-gate */ 164*7c478bd9Sstevel@tonic-gate 165*7c478bd9Sstevel@tonic-gate void 166*7c478bd9Sstevel@tonic-gate mac_stat_create(mac_impl_t *mip) 167*7c478bd9Sstevel@tonic-gate { 168*7c478bd9Sstevel@tonic-gate mac_t *mp = mip->mi_mp; 169*7c478bd9Sstevel@tonic-gate kstat_t *ksp; 170*7c478bd9Sstevel@tonic-gate kstat_named_t *knp; 171*7c478bd9Sstevel@tonic-gate uint_t i; 172*7c478bd9Sstevel@tonic-gate uint_t count; 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate count = 0; 175*7c478bd9Sstevel@tonic-gate for (i = 0; i < STAT_INFO_COUNT; i++) { 176*7c478bd9Sstevel@tonic-gate if (mp->m_info.mi_stat[i_mac_si[i].msi_stat]) 177*7c478bd9Sstevel@tonic-gate count++; 178*7c478bd9Sstevel@tonic-gate } 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate if ((ksp = kstat_create(mip->mi_dev, mip->mi_port, mip->mi_name, 181*7c478bd9Sstevel@tonic-gate "mac", KSTAT_TYPE_NAMED, count + 3, 0)) == NULL) 182*7c478bd9Sstevel@tonic-gate return; 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate ksp->ks_update = i_mac_stat_update; 185*7c478bd9Sstevel@tonic-gate ksp->ks_private = (void *)mip; 186*7c478bd9Sstevel@tonic-gate mip->mi_ksp = ksp; 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate knp = (kstat_named_t *)ksp->ks_data; 189*7c478bd9Sstevel@tonic-gate for (i = 0; i < STAT_INFO_COUNT; i++) { 190*7c478bd9Sstevel@tonic-gate if (!(mp->m_info.mi_stat[i_mac_si[i].msi_stat])) 191*7c478bd9Sstevel@tonic-gate continue; 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate kstat_named_init(knp, i_mac_si[i].msi_name, 194*7c478bd9Sstevel@tonic-gate i_mac_si[i].msi_type); 195*7c478bd9Sstevel@tonic-gate knp++; 196*7c478bd9Sstevel@tonic-gate --count; 197*7c478bd9Sstevel@tonic-gate } 198*7c478bd9Sstevel@tonic-gate ASSERT(count == 0); 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate kstat_named_init(knp++, "link_state", KSTAT_DATA_UINT32); 201*7c478bd9Sstevel@tonic-gate kstat_named_init(knp++, "link_up", KSTAT_DATA_UINT32); 202*7c478bd9Sstevel@tonic-gate kstat_named_init(knp, "promisc", KSTAT_DATA_UINT32); 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate kstat_install(ksp); 205*7c478bd9Sstevel@tonic-gate } 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 208*7c478bd9Sstevel@tonic-gate void 209*7c478bd9Sstevel@tonic-gate mac_stat_destroy(mac_impl_t *mip) 210*7c478bd9Sstevel@tonic-gate { 211*7c478bd9Sstevel@tonic-gate kstat_delete(mip->mi_ksp); 212*7c478bd9Sstevel@tonic-gate mip->mi_ksp = NULL; 213*7c478bd9Sstevel@tonic-gate } 214