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 5*2311Sseb * Common Development and Distribution License (the "License"). 6*2311Sseb * 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*2311Sseb * Copyright 2006 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> 380Sstevel@tonic-gate #include <sys/ctype.h> 390Sstevel@tonic-gate #include <sys/dls.h> 400Sstevel@tonic-gate #include <sys/dls_impl.h> 410Sstevel@tonic-gate 42*2311Sseb static mac_stat_info_t i_dls_si[] = { 43*2311Sseb { MAC_STAT_IFSPEED, "ifspeed", KSTAT_DATA_UINT64, 0 }, 44*2311Sseb { MAC_STAT_MULTIRCV, "multircv", KSTAT_DATA_UINT32, 0 }, 45*2311Sseb { MAC_STAT_BRDCSTRCV, "brdcstrcv", KSTAT_DATA_UINT32, 0 }, 46*2311Sseb { MAC_STAT_MULTIXMT, "multixmt", KSTAT_DATA_UINT32, 0 }, 47*2311Sseb { MAC_STAT_BRDCSTXMT, "brdcstxmt", KSTAT_DATA_UINT32, 0 }, 48*2311Sseb { MAC_STAT_NORCVBUF, "norcvbuf", KSTAT_DATA_UINT32, 0 }, 49*2311Sseb { MAC_STAT_IERRORS, "ierrors", KSTAT_DATA_UINT32, 0 }, 50*2311Sseb { MAC_STAT_NOXMTBUF, "noxmtbuf", KSTAT_DATA_UINT32, 0 }, 51*2311Sseb { MAC_STAT_OERRORS, "oerrors", KSTAT_DATA_UINT32, 0 }, 52*2311Sseb { MAC_STAT_COLLISIONS, "collisions", KSTAT_DATA_UINT32, 0 }, 53*2311Sseb { MAC_STAT_RBYTES, "rbytes", KSTAT_DATA_UINT32, 0 }, 54*2311Sseb { MAC_STAT_IPACKETS, "ipackets", KSTAT_DATA_UINT32, 0 }, 55*2311Sseb { MAC_STAT_OBYTES, "obytes", KSTAT_DATA_UINT32, 0 }, 56*2311Sseb { MAC_STAT_OPACKETS, "opackets", KSTAT_DATA_UINT32, 0 }, 57*2311Sseb { MAC_STAT_RBYTES, "rbytes64", KSTAT_DATA_UINT64, 0 }, 58*2311Sseb { MAC_STAT_IPACKETS, "ipackets64", KSTAT_DATA_UINT64, 0 }, 59*2311Sseb { MAC_STAT_OBYTES, "obytes64", KSTAT_DATA_UINT64, 0 }, 60*2311Sseb { MAC_STAT_OPACKETS, "opackets64", KSTAT_DATA_UINT64, 0 } 610Sstevel@tonic-gate }; 620Sstevel@tonic-gate 630Sstevel@tonic-gate #define STAT_INFO_COUNT (sizeof (i_dls_si) / sizeof (i_dls_si[0])) 640Sstevel@tonic-gate 650Sstevel@tonic-gate /* 660Sstevel@tonic-gate * Private functions. 670Sstevel@tonic-gate */ 680Sstevel@tonic-gate 690Sstevel@tonic-gate static int 700Sstevel@tonic-gate i_dls_stat_update(kstat_t *ksp, int rw) 710Sstevel@tonic-gate { 720Sstevel@tonic-gate dls_vlan_t *dvp = ksp->ks_private; 730Sstevel@tonic-gate dls_link_t *dlp = dvp->dv_dlp; 740Sstevel@tonic-gate kstat_named_t *knp; 750Sstevel@tonic-gate uint_t i; 760Sstevel@tonic-gate uint64_t val; 770Sstevel@tonic-gate int err; 780Sstevel@tonic-gate 790Sstevel@tonic-gate if (rw != KSTAT_READ) 800Sstevel@tonic-gate return (EACCES); 810Sstevel@tonic-gate 820Sstevel@tonic-gate if ((err = dls_mac_hold(dlp)) != 0) 830Sstevel@tonic-gate return (err); 840Sstevel@tonic-gate 850Sstevel@tonic-gate knp = (kstat_named_t *)ksp->ks_data; 860Sstevel@tonic-gate for (i = 0; i < STAT_INFO_COUNT; i++) { 87*2311Sseb val = mac_stat_get(dlp->dl_mh, i_dls_si[i].msi_stat); 880Sstevel@tonic-gate 89*2311Sseb switch (i_dls_si[i].msi_type) { 900Sstevel@tonic-gate case KSTAT_DATA_UINT64: 910Sstevel@tonic-gate knp->value.ui64 = val; 920Sstevel@tonic-gate break; 930Sstevel@tonic-gate case KSTAT_DATA_UINT32: 940Sstevel@tonic-gate knp->value.ui32 = (uint32_t)val; 950Sstevel@tonic-gate break; 960Sstevel@tonic-gate default: 970Sstevel@tonic-gate ASSERT(B_FALSE); 980Sstevel@tonic-gate } 990Sstevel@tonic-gate 1000Sstevel@tonic-gate knp++; 1010Sstevel@tonic-gate } 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate knp->value.ui32 = dlp->dl_unknowns; 1040Sstevel@tonic-gate dls_mac_rele(dlp); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate return (0); 1070Sstevel@tonic-gate } 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate /* 1100Sstevel@tonic-gate * Exported functions. 1110Sstevel@tonic-gate */ 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate void 1141184Skrgopi dls_mac_stat_create(dls_vlan_t *dvp) 1150Sstevel@tonic-gate { 1160Sstevel@tonic-gate dls_link_t *dlp = dvp->dv_dlp; 1170Sstevel@tonic-gate char module[IFNAMSIZ]; 1180Sstevel@tonic-gate uint_t instance; 1190Sstevel@tonic-gate kstat_t *ksp; 1200Sstevel@tonic-gate kstat_named_t *knp; 1210Sstevel@tonic-gate uint_t i; 1220Sstevel@tonic-gate int err; 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate if (dls_mac_hold(dlp) != 0) 1250Sstevel@tonic-gate return; 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate err = ddi_parse(dvp->dv_name, module, &instance); 1280Sstevel@tonic-gate ASSERT(err == DDI_SUCCESS); 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate if ((ksp = kstat_create(module, instance, NULL, "net", 131*2311Sseb KSTAT_TYPE_NAMED, STAT_INFO_COUNT + 1, 0)) == NULL) 1320Sstevel@tonic-gate goto done; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate ksp->ks_update = i_dls_stat_update; 1350Sstevel@tonic-gate ksp->ks_private = (void *)dvp; 1360Sstevel@tonic-gate dvp->dv_ksp = ksp; 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate knp = (kstat_named_t *)ksp->ks_data; 1390Sstevel@tonic-gate for (i = 0; i < STAT_INFO_COUNT; i++) { 140*2311Sseb kstat_named_init(knp, i_dls_si[i].msi_name, 141*2311Sseb i_dls_si[i].msi_type); 1420Sstevel@tonic-gate knp++; 1430Sstevel@tonic-gate } 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate kstat_named_init(knp, "unknowns", KSTAT_DATA_UINT32); 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate kstat_install(ksp); 1480Sstevel@tonic-gate done: 1490Sstevel@tonic-gate dls_mac_rele(dlp); 1500Sstevel@tonic-gate } 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate void 1531184Skrgopi dls_mac_stat_destroy(dls_vlan_t *dvp) 1540Sstevel@tonic-gate { 1550Sstevel@tonic-gate kstat_delete(dvp->dv_ksp); 1560Sstevel@tonic-gate dvp->dv_ksp = NULL; 1570Sstevel@tonic-gate } 158