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