106db247cSraghuram /* 206db247cSraghuram * CDDL HEADER START 306db247cSraghuram * 406db247cSraghuram * The contents of this file are subject to the terms of the 506db247cSraghuram * Common Development and Distribution License (the "License"). 606db247cSraghuram * You may not use this file except in compliance with the License. 706db247cSraghuram * 806db247cSraghuram * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 906db247cSraghuram * or http://www.opensolaris.org/os/licensing. 1006db247cSraghuram * See the License for the specific language governing permissions 1106db247cSraghuram * and limitations under the License. 1206db247cSraghuram * 1306db247cSraghuram * When distributing Covered Code, include this CDDL HEADER in each 1406db247cSraghuram * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1506db247cSraghuram * If applicable, add the following below this CDDL HEADER, with the 1606db247cSraghuram * fields enclosed by brackets "[]" replaced with your own identifying 1706db247cSraghuram * information: Portions Copyright [yyyy] [name of copyright owner] 1806db247cSraghuram * 1906db247cSraghuram * CDDL HEADER END 2006db247cSraghuram */ 2106db247cSraghuram 2206db247cSraghuram /* 23*7bd3a2e2SSriharsha Basavapatna * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 2406db247cSraghuram * Use is subject to license terms. 2506db247cSraghuram */ 2606db247cSraghuram 2706db247cSraghuram #include <sys/types.h> 2806db247cSraghuram #include <sys/errno.h> 2906db247cSraghuram #include <sys/param.h> 3006db247cSraghuram #include <sys/stream.h> 3106db247cSraghuram #include <sys/strsubr.h> 3206db247cSraghuram #include <sys/kmem.h> 3306db247cSraghuram #include <sys/ksynch.h> 3406db247cSraghuram #include <sys/stat.h> 3506db247cSraghuram #include <sys/vgen_stats.h> 3606db247cSraghuram 3706db247cSraghuram /* 3806db247cSraghuram * A set of common kstat statistics related functions that are 3906db247cSraghuram * used by both vnet and vsw drivers to maintain the statistics specific 4006db247cSraghuram * LDCs. 4106db247cSraghuram */ 4206db247cSraghuram 4306db247cSraghuram /* 4406db247cSraghuram * Setup kstats for the LDC statistics. 4506db247cSraghuram * NOTE: the synchronization for the statistics is the 4606db247cSraghuram * responsibility of the caller. 4706db247cSraghuram */ 4806db247cSraghuram kstat_t * 4906db247cSraghuram vgen_setup_kstats(char *ks_mod, int instance, 5006db247cSraghuram char *ks_name, vgen_stats_t *statsp) 5106db247cSraghuram { 5206db247cSraghuram kstat_t *ksp; 5306db247cSraghuram vgen_kstats_t *ldckp; 5406db247cSraghuram size_t size; 5506db247cSraghuram 5606db247cSraghuram size = sizeof (vgen_kstats_t) / sizeof (kstat_named_t); 5706db247cSraghuram ksp = kstat_create(ks_mod, instance, ks_name, "net", KSTAT_TYPE_NAMED, 5806db247cSraghuram size, 0); 5906db247cSraghuram if (ksp == NULL) { 6006db247cSraghuram return (NULL); 6106db247cSraghuram } 6206db247cSraghuram 6306db247cSraghuram ldckp = (vgen_kstats_t *)ksp->ks_data; 6406db247cSraghuram kstat_named_init(&ldckp->ipackets, "ipackets", 6506db247cSraghuram KSTAT_DATA_ULONG); 6606db247cSraghuram kstat_named_init(&ldckp->ipackets64, "ipackets64", 6706db247cSraghuram KSTAT_DATA_ULONGLONG); 6806db247cSraghuram kstat_named_init(&ldckp->ierrors, "ierrors", 6906db247cSraghuram KSTAT_DATA_ULONG); 7006db247cSraghuram kstat_named_init(&ldckp->opackets, "opackets", 7106db247cSraghuram KSTAT_DATA_ULONG); 7206db247cSraghuram kstat_named_init(&ldckp->opackets64, "opackets64", 7306db247cSraghuram KSTAT_DATA_ULONGLONG); 7406db247cSraghuram kstat_named_init(&ldckp->oerrors, "oerrors", 7506db247cSraghuram KSTAT_DATA_ULONG); 7606db247cSraghuram 7706db247cSraghuram 7806db247cSraghuram /* MIB II kstat variables */ 7906db247cSraghuram kstat_named_init(&ldckp->rbytes, "rbytes", 8006db247cSraghuram KSTAT_DATA_ULONG); 8106db247cSraghuram kstat_named_init(&ldckp->rbytes64, "rbytes64", 8206db247cSraghuram KSTAT_DATA_ULONGLONG); 8306db247cSraghuram kstat_named_init(&ldckp->obytes, "obytes", 8406db247cSraghuram KSTAT_DATA_ULONG); 8506db247cSraghuram kstat_named_init(&ldckp->obytes64, "obytes64", 8606db247cSraghuram KSTAT_DATA_ULONGLONG); 8706db247cSraghuram kstat_named_init(&ldckp->multircv, "multircv", 8806db247cSraghuram KSTAT_DATA_ULONG); 8906db247cSraghuram kstat_named_init(&ldckp->multixmt, "multixmt", 9006db247cSraghuram KSTAT_DATA_ULONG); 9106db247cSraghuram kstat_named_init(&ldckp->brdcstrcv, "brdcstrcv", 9206db247cSraghuram KSTAT_DATA_ULONG); 9306db247cSraghuram kstat_named_init(&ldckp->brdcstxmt, "brdcstxmt", 9406db247cSraghuram KSTAT_DATA_ULONG); 9506db247cSraghuram kstat_named_init(&ldckp->norcvbuf, "norcvbuf", 9606db247cSraghuram KSTAT_DATA_ULONG); 9706db247cSraghuram kstat_named_init(&ldckp->noxmtbuf, "noxmtbuf", 9806db247cSraghuram KSTAT_DATA_ULONG); 9906db247cSraghuram 10006db247cSraghuram /* Tx stats */ 10106db247cSraghuram kstat_named_init(&ldckp->tx_no_desc, "tx_no_desc", 10206db247cSraghuram KSTAT_DATA_ULONG); 103f0ca1d9aSsb155480 kstat_named_init(&ldckp->tx_qfull, "tx_qfull", 104f0ca1d9aSsb155480 KSTAT_DATA_ULONG); 105f0ca1d9aSsb155480 kstat_named_init(&ldckp->tx_pri_fail, "tx_pri_fail", 106f0ca1d9aSsb155480 KSTAT_DATA_ULONG); 107f0ca1d9aSsb155480 kstat_named_init(&ldckp->tx_pri_packets, "tx_pri_packets", 108f0ca1d9aSsb155480 KSTAT_DATA_ULONGLONG); 109f0ca1d9aSsb155480 kstat_named_init(&ldckp->tx_pri_bytes, "tx_pri_bytes", 110f0ca1d9aSsb155480 KSTAT_DATA_ULONGLONG); 11106db247cSraghuram 11206db247cSraghuram /* Rx stats */ 11306db247cSraghuram kstat_named_init(&ldckp->rx_allocb_fail, "rx_allocb_fail", 11406db247cSraghuram KSTAT_DATA_ULONG); 11506db247cSraghuram kstat_named_init(&ldckp->rx_vio_allocb_fail, "rx_vio_allocb_fail", 11606db247cSraghuram KSTAT_DATA_ULONG); 11706db247cSraghuram kstat_named_init(&ldckp->rx_lost_pkts, "rx_lost_pkts", 11806db247cSraghuram KSTAT_DATA_ULONG); 119f0ca1d9aSsb155480 kstat_named_init(&ldckp->rx_pri_fail, "rx_pri_fail", 120f0ca1d9aSsb155480 KSTAT_DATA_ULONG); 121f0ca1d9aSsb155480 kstat_named_init(&ldckp->rx_pri_packets, "rx_pri_packets", 122f0ca1d9aSsb155480 KSTAT_DATA_ULONGLONG); 123f0ca1d9aSsb155480 kstat_named_init(&ldckp->rx_pri_bytes, "rx_pri_bytes", 124f0ca1d9aSsb155480 KSTAT_DATA_ULONGLONG); 12506db247cSraghuram 12606db247cSraghuram /* Interrupt stats */ 12706db247cSraghuram kstat_named_init(&ldckp->callbacks, "callbacks", 12806db247cSraghuram KSTAT_DATA_ULONG); 129*7bd3a2e2SSriharsha Basavapatna kstat_named_init(&ldckp->dring_data_msgs_sent, "dring_data_msgs_sent", 13006db247cSraghuram KSTAT_DATA_ULONG); 131*7bd3a2e2SSriharsha Basavapatna kstat_named_init(&ldckp->dring_data_acks_rcvd, "dring_data_acks_rcvd", 13206db247cSraghuram KSTAT_DATA_ULONG); 133*7bd3a2e2SSriharsha Basavapatna kstat_named_init(&ldckp->dring_stopped_acks_rcvd, 134*7bd3a2e2SSriharsha Basavapatna "dring_stopped_acks_rcvd", KSTAT_DATA_ULONG); 135*7bd3a2e2SSriharsha Basavapatna kstat_named_init(&ldckp->dring_data_msgs_rcvd, "dring_data_msgs_rcvd", 13606db247cSraghuram KSTAT_DATA_ULONG); 137*7bd3a2e2SSriharsha Basavapatna kstat_named_init(&ldckp->dring_data_acks_sent, "dring_data_acks_sent", 138*7bd3a2e2SSriharsha Basavapatna KSTAT_DATA_ULONG); 139*7bd3a2e2SSriharsha Basavapatna kstat_named_init(&ldckp->dring_stopped_acks_sent, 140*7bd3a2e2SSriharsha Basavapatna "dring_stopped_acks_sent", KSTAT_DATA_ULONG); 141*7bd3a2e2SSriharsha Basavapatna kstat_named_init(&ldckp->dring_mode, "dring_mode", KSTAT_DATA_ULONG); 14206db247cSraghuram 14306db247cSraghuram ksp->ks_update = vgen_kstat_update; 14406db247cSraghuram ksp->ks_private = (void *)statsp; 14506db247cSraghuram kstat_install(ksp); 14606db247cSraghuram return (ksp); 14706db247cSraghuram } 14806db247cSraghuram 14906db247cSraghuram /* 15006db247cSraghuram * Destroy kstats. 15106db247cSraghuram */ 15206db247cSraghuram void 15306db247cSraghuram vgen_destroy_kstats(kstat_t *ksp) 15406db247cSraghuram { 15506db247cSraghuram if (ksp != NULL) 15606db247cSraghuram kstat_delete(ksp); 15706db247cSraghuram } 15806db247cSraghuram 15906db247cSraghuram /* 16006db247cSraghuram * Update the kstats. 16106db247cSraghuram */ 16206db247cSraghuram int 16306db247cSraghuram vgen_kstat_update(kstat_t *ksp, int rw) 16406db247cSraghuram { 16506db247cSraghuram vgen_stats_t *statsp; 16606db247cSraghuram vgen_kstats_t *ldckp; 16706db247cSraghuram 16806db247cSraghuram statsp = (vgen_stats_t *)ksp->ks_private; 16906db247cSraghuram ldckp = (vgen_kstats_t *)ksp->ks_data; 17006db247cSraghuram 17106db247cSraghuram if (rw == KSTAT_READ) { 172f0ca1d9aSsb155480 ldckp->ipackets.value.ul = (uint32_t)statsp->ipackets + 173f0ca1d9aSsb155480 (uint32_t)statsp->rx_pri_packets; 174f0ca1d9aSsb155480 ldckp->ipackets64.value.ull = statsp->ipackets + 175f0ca1d9aSsb155480 statsp->rx_pri_packets; 17606db247cSraghuram ldckp->ierrors.value.ul = statsp->ierrors; 177f0ca1d9aSsb155480 ldckp->opackets.value.ul = (uint32_t)statsp->opackets + 178f0ca1d9aSsb155480 (uint32_t)statsp->tx_pri_packets; 179f0ca1d9aSsb155480 ldckp->opackets64.value.ull = statsp->opackets + 180f0ca1d9aSsb155480 statsp->tx_pri_packets; 18106db247cSraghuram ldckp->oerrors.value.ul = statsp->oerrors; 18206db247cSraghuram 18306db247cSraghuram /* 18406db247cSraghuram * MIB II kstat variables 18506db247cSraghuram */ 186f0ca1d9aSsb155480 ldckp->rbytes.value.ul = (uint32_t)statsp->rbytes + 187f0ca1d9aSsb155480 (uint32_t)statsp->rx_pri_bytes; 188f0ca1d9aSsb155480 ldckp->rbytes64.value.ull = statsp->rbytes + 189f0ca1d9aSsb155480 statsp->rx_pri_bytes; 190f0ca1d9aSsb155480 ldckp->obytes.value.ul = (uint32_t)statsp->obytes + 191f0ca1d9aSsb155480 (uint32_t)statsp->tx_pri_bytes; 192f0ca1d9aSsb155480 ldckp->obytes64.value.ull = statsp->obytes + 193f0ca1d9aSsb155480 statsp->tx_pri_bytes; 19406db247cSraghuram ldckp->multircv.value.ul = statsp->multircv; 19506db247cSraghuram ldckp->multixmt.value.ul = statsp->multixmt; 19606db247cSraghuram ldckp->brdcstrcv.value.ul = statsp->brdcstrcv; 19706db247cSraghuram ldckp->brdcstxmt.value.ul = statsp->brdcstxmt; 19806db247cSraghuram ldckp->norcvbuf.value.ul = statsp->norcvbuf; 19906db247cSraghuram ldckp->noxmtbuf.value.ul = statsp->noxmtbuf; 20006db247cSraghuram 20106db247cSraghuram ldckp->tx_no_desc.value.ul = statsp->tx_no_desc; 202f0ca1d9aSsb155480 ldckp->tx_qfull.value.ul = statsp->tx_qfull; 203f0ca1d9aSsb155480 ldckp->tx_pri_fail.value.ul = statsp->tx_pri_fail; 204f0ca1d9aSsb155480 ldckp->tx_pri_packets.value.ull = statsp->tx_pri_packets; 205f0ca1d9aSsb155480 ldckp->tx_pri_bytes.value.ull = statsp->tx_pri_bytes; 20606db247cSraghuram 20706db247cSraghuram ldckp->rx_allocb_fail.value.ul = statsp->rx_allocb_fail; 20806db247cSraghuram ldckp->rx_vio_allocb_fail.value.ul = statsp->rx_vio_allocb_fail; 20906db247cSraghuram ldckp->rx_lost_pkts.value.ul = statsp->rx_lost_pkts; 210f0ca1d9aSsb155480 ldckp->rx_pri_fail.value.ul = statsp->rx_pri_fail; 211f0ca1d9aSsb155480 ldckp->rx_pri_packets.value.ull = statsp->rx_pri_packets; 212f0ca1d9aSsb155480 ldckp->rx_pri_bytes.value.ull = statsp->rx_pri_bytes; 21306db247cSraghuram 21406db247cSraghuram ldckp->callbacks.value.ul = statsp->callbacks; 215*7bd3a2e2SSriharsha Basavapatna 216*7bd3a2e2SSriharsha Basavapatna ldckp->dring_data_msgs_sent.value.ul = 217*7bd3a2e2SSriharsha Basavapatna statsp->dring_data_msgs_sent; 218*7bd3a2e2SSriharsha Basavapatna ldckp->dring_data_acks_rcvd.value.ul = 219*7bd3a2e2SSriharsha Basavapatna statsp->dring_data_acks_rcvd; 220*7bd3a2e2SSriharsha Basavapatna ldckp->dring_stopped_acks_rcvd.value.ul = 221*7bd3a2e2SSriharsha Basavapatna statsp->dring_stopped_acks_rcvd; 222*7bd3a2e2SSriharsha Basavapatna ldckp->dring_data_msgs_rcvd.value.ul = 223*7bd3a2e2SSriharsha Basavapatna statsp->dring_data_msgs_rcvd; 224*7bd3a2e2SSriharsha Basavapatna ldckp->dring_data_acks_sent.value.ul = 225*7bd3a2e2SSriharsha Basavapatna statsp->dring_data_acks_sent; 226*7bd3a2e2SSriharsha Basavapatna ldckp->dring_stopped_acks_sent.value.ul = 227*7bd3a2e2SSriharsha Basavapatna statsp->dring_stopped_acks_sent; 228*7bd3a2e2SSriharsha Basavapatna ldckp->dring_mode.value.ul = statsp->dring_mode; 22906db247cSraghuram } else { 23006db247cSraghuram statsp->ipackets = ldckp->ipackets64.value.ull; 23106db247cSraghuram statsp->ierrors = ldckp->ierrors.value.ul; 23206db247cSraghuram statsp->opackets = ldckp->opackets64.value.ull; 23306db247cSraghuram statsp->oerrors = ldckp->oerrors.value.ul; 23406db247cSraghuram 23506db247cSraghuram /* 23606db247cSraghuram * MIB II kstat variables 23706db247cSraghuram */ 23806db247cSraghuram statsp->rbytes = ldckp->rbytes64.value.ull; 23906db247cSraghuram statsp->obytes = ldckp->obytes64.value.ull; 24006db247cSraghuram statsp->multircv = ldckp->multircv.value.ul; 24106db247cSraghuram statsp->multixmt = ldckp->multixmt.value.ul; 24206db247cSraghuram statsp->brdcstrcv = ldckp->brdcstrcv.value.ul; 24306db247cSraghuram statsp->brdcstxmt = ldckp->brdcstxmt.value.ul; 24406db247cSraghuram statsp->norcvbuf = ldckp->norcvbuf.value.ul; 24506db247cSraghuram statsp->noxmtbuf = ldckp->noxmtbuf.value.ul; 24606db247cSraghuram 24706db247cSraghuram statsp->tx_no_desc = ldckp->tx_no_desc.value.ul; 248f0ca1d9aSsb155480 statsp->tx_qfull = ldckp->tx_qfull.value.ul; 249f0ca1d9aSsb155480 statsp->tx_pri_fail = ldckp->tx_pri_fail.value.ul; 250f0ca1d9aSsb155480 statsp->tx_pri_packets = ldckp->tx_pri_packets.value.ull; 251f0ca1d9aSsb155480 statsp->tx_pri_bytes = ldckp->tx_pri_bytes.value.ull; 25206db247cSraghuram 25306db247cSraghuram statsp->rx_allocb_fail = ldckp->rx_allocb_fail.value.ul; 25406db247cSraghuram statsp->rx_vio_allocb_fail = ldckp->rx_vio_allocb_fail.value.ul; 25506db247cSraghuram statsp->rx_lost_pkts = ldckp->rx_lost_pkts.value.ul; 256f0ca1d9aSsb155480 statsp->rx_pri_fail = ldckp->rx_pri_fail.value.ul; 257f0ca1d9aSsb155480 statsp->rx_pri_packets = ldckp->rx_pri_packets.value.ull; 258f0ca1d9aSsb155480 statsp->rx_pri_bytes = ldckp->rx_pri_bytes.value.ull; 25906db247cSraghuram 26006db247cSraghuram statsp->callbacks = ldckp->callbacks.value.ul; 261*7bd3a2e2SSriharsha Basavapatna statsp->dring_data_msgs_sent = 262*7bd3a2e2SSriharsha Basavapatna ldckp->dring_data_msgs_sent.value.ul; 263*7bd3a2e2SSriharsha Basavapatna statsp->dring_data_acks_rcvd = 264*7bd3a2e2SSriharsha Basavapatna ldckp->dring_data_acks_rcvd.value.ul; 265*7bd3a2e2SSriharsha Basavapatna statsp->dring_stopped_acks_rcvd = 266*7bd3a2e2SSriharsha Basavapatna ldckp->dring_stopped_acks_rcvd.value.ul; 267*7bd3a2e2SSriharsha Basavapatna statsp->dring_data_msgs_rcvd = 268*7bd3a2e2SSriharsha Basavapatna ldckp->dring_data_msgs_rcvd.value.ul; 269*7bd3a2e2SSriharsha Basavapatna statsp->dring_data_acks_sent = 270*7bd3a2e2SSriharsha Basavapatna ldckp->dring_data_acks_sent.value.ul; 271*7bd3a2e2SSriharsha Basavapatna statsp->dring_stopped_acks_sent = 272*7bd3a2e2SSriharsha Basavapatna ldckp->dring_stopped_acks_sent.value.ul; 273*7bd3a2e2SSriharsha Basavapatna statsp->dring_mode = ldckp->dring_mode.value.ul; 27406db247cSraghuram } 27506db247cSraghuram 27606db247cSraghuram return (0); 27706db247cSraghuram } 278