10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52311Sseb * Common Development and Distribution License (the "License"). 62311Sseb * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*5895Syz147064 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * Data-Link Services Module 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/sysmacros.h> 340Sstevel@tonic-gate #include <sys/atomic.h> 350Sstevel@tonic-gate #include <sys/kstat.h> 360Sstevel@tonic-gate #include <sys/vlan.h> 370Sstevel@tonic-gate #include <sys/mac.h> 38*5895Syz147064 #include <sys/mac_ether.h> 390Sstevel@tonic-gate #include <sys/ctype.h> 400Sstevel@tonic-gate #include <sys/dls.h> 410Sstevel@tonic-gate #include <sys/dls_impl.h> 420Sstevel@tonic-gate 432311Sseb static mac_stat_info_t i_dls_si[] = { 442311Sseb { MAC_STAT_IFSPEED, "ifspeed", KSTAT_DATA_UINT64, 0 }, 452311Sseb { MAC_STAT_MULTIRCV, "multircv", KSTAT_DATA_UINT32, 0 }, 462311Sseb { MAC_STAT_BRDCSTRCV, "brdcstrcv", KSTAT_DATA_UINT32, 0 }, 472311Sseb { MAC_STAT_MULTIXMT, "multixmt", KSTAT_DATA_UINT32, 0 }, 482311Sseb { MAC_STAT_BRDCSTXMT, "brdcstxmt", KSTAT_DATA_UINT32, 0 }, 492311Sseb { MAC_STAT_NORCVBUF, "norcvbuf", KSTAT_DATA_UINT32, 0 }, 502311Sseb { MAC_STAT_IERRORS, "ierrors", KSTAT_DATA_UINT32, 0 }, 512311Sseb { MAC_STAT_NOXMTBUF, "noxmtbuf", KSTAT_DATA_UINT32, 0 }, 522311Sseb { MAC_STAT_OERRORS, "oerrors", KSTAT_DATA_UINT32, 0 }, 532311Sseb { MAC_STAT_COLLISIONS, "collisions", KSTAT_DATA_UINT32, 0 }, 542311Sseb { MAC_STAT_RBYTES, "rbytes", KSTAT_DATA_UINT32, 0 }, 552311Sseb { MAC_STAT_IPACKETS, "ipackets", KSTAT_DATA_UINT32, 0 }, 562311Sseb { MAC_STAT_OBYTES, "obytes", KSTAT_DATA_UINT32, 0 }, 572311Sseb { MAC_STAT_OPACKETS, "opackets", KSTAT_DATA_UINT32, 0 }, 582311Sseb { MAC_STAT_RBYTES, "rbytes64", KSTAT_DATA_UINT64, 0 }, 592311Sseb { MAC_STAT_IPACKETS, "ipackets64", KSTAT_DATA_UINT64, 0 }, 602311Sseb { MAC_STAT_OBYTES, "obytes64", KSTAT_DATA_UINT64, 0 }, 61*5895Syz147064 { MAC_STAT_OPACKETS, "opackets64", KSTAT_DATA_UINT64, 0 }, 62*5895Syz147064 { MAC_STAT_LINK_STATE, "link_state", KSTAT_DATA_UINT32, 63*5895Syz147064 (uint64_t)LINK_STATE_UNKNOWN} 640Sstevel@tonic-gate }; 650Sstevel@tonic-gate 660Sstevel@tonic-gate #define STAT_INFO_COUNT (sizeof (i_dls_si) / sizeof (i_dls_si[0])) 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * Private functions. 700Sstevel@tonic-gate */ 710Sstevel@tonic-gate 720Sstevel@tonic-gate static int 73*5895Syz147064 i_dls_mac_stat_update(kstat_t *ksp, int rw) 740Sstevel@tonic-gate { 750Sstevel@tonic-gate dls_vlan_t *dvp = ksp->ks_private; 76*5895Syz147064 77*5895Syz147064 return (dls_stat_update(ksp, dvp, rw)); 78*5895Syz147064 } 79*5895Syz147064 80*5895Syz147064 /* 81*5895Syz147064 * Exported functions. 82*5895Syz147064 */ 83*5895Syz147064 int 84*5895Syz147064 dls_stat_update(kstat_t *ksp, dls_vlan_t *dvp, int rw) 85*5895Syz147064 { 860Sstevel@tonic-gate dls_link_t *dlp = dvp->dv_dlp; 870Sstevel@tonic-gate kstat_named_t *knp; 880Sstevel@tonic-gate uint_t i; 890Sstevel@tonic-gate uint64_t val; 900Sstevel@tonic-gate int err; 910Sstevel@tonic-gate 920Sstevel@tonic-gate if (rw != KSTAT_READ) 930Sstevel@tonic-gate return (EACCES); 940Sstevel@tonic-gate 950Sstevel@tonic-gate if ((err = dls_mac_hold(dlp)) != 0) 960Sstevel@tonic-gate return (err); 970Sstevel@tonic-gate 980Sstevel@tonic-gate knp = (kstat_named_t *)ksp->ks_data; 990Sstevel@tonic-gate for (i = 0; i < STAT_INFO_COUNT; i++) { 1002311Sseb val = mac_stat_get(dlp->dl_mh, i_dls_si[i].msi_stat); 1010Sstevel@tonic-gate 1022311Sseb switch (i_dls_si[i].msi_type) { 1030Sstevel@tonic-gate case KSTAT_DATA_UINT64: 1040Sstevel@tonic-gate knp->value.ui64 = val; 1050Sstevel@tonic-gate break; 1060Sstevel@tonic-gate case KSTAT_DATA_UINT32: 1070Sstevel@tonic-gate knp->value.ui32 = (uint32_t)val; 1080Sstevel@tonic-gate break; 1090Sstevel@tonic-gate default: 1100Sstevel@tonic-gate ASSERT(B_FALSE); 1110Sstevel@tonic-gate } 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate knp++; 1140Sstevel@tonic-gate } 1150Sstevel@tonic-gate 116*5895Syz147064 /* 117*5895Syz147064 * Ethernet specific kstat "link_duplex" 118*5895Syz147064 */ 119*5895Syz147064 if (dlp->dl_mip->mi_nativemedia != DL_ETHER) { 120*5895Syz147064 knp->value.ui32 = LINK_DUPLEX_UNKNOWN; 121*5895Syz147064 } else { 122*5895Syz147064 val = mac_stat_get(dlp->dl_mh, ETHER_STAT_LINK_DUPLEX); 123*5895Syz147064 knp->value.ui32 = (uint32_t)val; 124*5895Syz147064 } 125*5895Syz147064 knp++; 1260Sstevel@tonic-gate knp->value.ui32 = dlp->dl_unknowns; 1270Sstevel@tonic-gate dls_mac_rele(dlp); 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate return (0); 1300Sstevel@tonic-gate } 1310Sstevel@tonic-gate 132*5895Syz147064 int 133*5895Syz147064 dls_stat_create(const char *module, int instance, const char *name, 134*5895Syz147064 int (*update)(struct kstat *, int), void *private, kstat_t **kspp) 1350Sstevel@tonic-gate { 136*5895Syz147064 kstat_t *ksp; 137*5895Syz147064 kstat_named_t *knp; 138*5895Syz147064 uint_t i; 1390Sstevel@tonic-gate 140*5895Syz147064 if ((ksp = kstat_create(module, instance, name, "net", 141*5895Syz147064 KSTAT_TYPE_NAMED, STAT_INFO_COUNT + 2, 0)) == NULL) { 142*5895Syz147064 return (EINVAL); 143*5895Syz147064 } 1440Sstevel@tonic-gate 145*5895Syz147064 ksp->ks_update = update; 146*5895Syz147064 ksp->ks_private = private; 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate knp = (kstat_named_t *)ksp->ks_data; 1490Sstevel@tonic-gate for (i = 0; i < STAT_INFO_COUNT; i++) { 1502311Sseb kstat_named_init(knp, i_dls_si[i].msi_name, 1512311Sseb i_dls_si[i].msi_type); 1520Sstevel@tonic-gate knp++; 1530Sstevel@tonic-gate } 1540Sstevel@tonic-gate 155*5895Syz147064 kstat_named_init(knp++, "link_duplex", KSTAT_DATA_UINT32); 1560Sstevel@tonic-gate kstat_named_init(knp, "unknowns", KSTAT_DATA_UINT32); 1570Sstevel@tonic-gate kstat_install(ksp); 158*5895Syz147064 *kspp = ksp; 159*5895Syz147064 return (0); 160*5895Syz147064 } 161*5895Syz147064 162*5895Syz147064 void 163*5895Syz147064 dls_mac_stat_create(dls_vlan_t *dvp) 164*5895Syz147064 { 165*5895Syz147064 kstat_t *ksp = NULL; 166*5895Syz147064 major_t major; 167*5895Syz147064 168*5895Syz147064 /* 169*5895Syz147064 * Create the legacy kstats to provide backward compatibility. 170*5895Syz147064 * These kstats need to be created even when this link does not 171*5895Syz147064 * have a link name, i.e., when the VLAN is accessed using its 172*5895Syz147064 * /dev node. 173*5895Syz147064 * 174*5895Syz147064 * Note that we only need to create the legacy kstats for GLDv3 175*5895Syz147064 * physical links, aggregation links which are created using 176*5895Syz147064 * the 'key' option, and any VLAN links created over them. 177*5895Syz147064 * This can be determined by checking its dv_ppa. 178*5895Syz147064 */ 179*5895Syz147064 ASSERT(dvp->dv_ksp == NULL); 180*5895Syz147064 if (dvp->dv_ppa >= MAC_MAX_MINOR) 181*5895Syz147064 return; 182*5895Syz147064 183*5895Syz147064 major = getmajor(dvp->dv_dev); 184*5895Syz147064 ASSERT(GLDV3_DRV(major) && (dvp->dv_ksp == NULL)); 185*5895Syz147064 186*5895Syz147064 if (dls_stat_create(ddi_major_to_name(major), 187*5895Syz147064 dvp->dv_id * 1000 + dvp->dv_ppa, NULL, 188*5895Syz147064 i_dls_mac_stat_update, dvp, &ksp) != 0) { 189*5895Syz147064 return; 190*5895Syz147064 } 191*5895Syz147064 ASSERT(ksp != NULL); 192*5895Syz147064 dvp->dv_ksp = ksp; 1930Sstevel@tonic-gate } 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate void 1961184Skrgopi dls_mac_stat_destroy(dls_vlan_t *dvp) 1970Sstevel@tonic-gate { 198*5895Syz147064 if (dvp->dv_ksp != NULL) { 199*5895Syz147064 kstat_delete(dvp->dv_ksp); 200*5895Syz147064 dvp->dv_ksp = NULL; 201*5895Syz147064 } 2020Sstevel@tonic-gate } 203