xref: /onnv-gate/usr/src/uts/common/io/dls/dls_stat.c (revision 10616:3be00c4a6835)
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*10616SSebastien.Roy@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*
270Sstevel@tonic-gate  * Data-Link Services Module
280Sstevel@tonic-gate  */
290Sstevel@tonic-gate 
308275SEric Cheng #include <sys/dld_impl.h>
315895Syz147064 #include <sys/mac_ether.h>
320Sstevel@tonic-gate 
332311Sseb static mac_stat_info_t	i_dls_si[] = {
342311Sseb 	{ MAC_STAT_IFSPEED, "ifspeed", KSTAT_DATA_UINT64, 0 },
352311Sseb 	{ MAC_STAT_MULTIRCV, "multircv", KSTAT_DATA_UINT32, 0 },
362311Sseb 	{ MAC_STAT_BRDCSTRCV, "brdcstrcv", KSTAT_DATA_UINT32, 0 },
372311Sseb 	{ MAC_STAT_MULTIXMT, "multixmt", KSTAT_DATA_UINT32, 0 },
382311Sseb 	{ MAC_STAT_BRDCSTXMT, "brdcstxmt", KSTAT_DATA_UINT32, 0 },
392311Sseb 	{ MAC_STAT_NORCVBUF, "norcvbuf", KSTAT_DATA_UINT32, 0 },
402311Sseb 	{ MAC_STAT_IERRORS, "ierrors", KSTAT_DATA_UINT32, 0 },
412311Sseb 	{ MAC_STAT_NOXMTBUF, "noxmtbuf", KSTAT_DATA_UINT32, 0 },
422311Sseb 	{ MAC_STAT_OERRORS, "oerrors", KSTAT_DATA_UINT32, 0 },
432311Sseb 	{ MAC_STAT_COLLISIONS, "collisions", KSTAT_DATA_UINT32, 0 },
442311Sseb 	{ MAC_STAT_RBYTES, "rbytes", KSTAT_DATA_UINT32, 0 },
452311Sseb 	{ MAC_STAT_IPACKETS, "ipackets", KSTAT_DATA_UINT32, 0 },
462311Sseb 	{ MAC_STAT_OBYTES, "obytes", KSTAT_DATA_UINT32, 0 },
472311Sseb 	{ MAC_STAT_OPACKETS, "opackets", KSTAT_DATA_UINT32, 0 },
482311Sseb 	{ MAC_STAT_RBYTES, "rbytes64", KSTAT_DATA_UINT64, 0 },
492311Sseb 	{ MAC_STAT_IPACKETS, "ipackets64", KSTAT_DATA_UINT64, 0 },
502311Sseb 	{ MAC_STAT_OBYTES, "obytes64", KSTAT_DATA_UINT64, 0 },
515895Syz147064 	{ MAC_STAT_OPACKETS, "opackets64", KSTAT_DATA_UINT64, 0 },
525895Syz147064 	{ MAC_STAT_LINK_STATE, "link_state", KSTAT_DATA_UINT32,
535895Syz147064 	    (uint64_t)LINK_STATE_UNKNOWN}
540Sstevel@tonic-gate };
550Sstevel@tonic-gate 
560Sstevel@tonic-gate #define	STAT_INFO_COUNT	(sizeof (i_dls_si) / sizeof (i_dls_si[0]))
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /*
595895Syz147064  * Exported functions.
605895Syz147064  */
615895Syz147064 int
dls_stat_update(kstat_t * ksp,dls_link_t * dlp,int rw)628275SEric Cheng dls_stat_update(kstat_t *ksp, dls_link_t *dlp, int rw)
635895Syz147064 {
640Sstevel@tonic-gate 	kstat_named_t	*knp;
650Sstevel@tonic-gate 	uint_t		i;
660Sstevel@tonic-gate 	uint64_t	val;
670Sstevel@tonic-gate 
680Sstevel@tonic-gate 	if (rw != KSTAT_READ)
690Sstevel@tonic-gate 		return (EACCES);
700Sstevel@tonic-gate 
710Sstevel@tonic-gate 	knp = (kstat_named_t *)ksp->ks_data;
720Sstevel@tonic-gate 	for (i = 0; i < STAT_INFO_COUNT; i++) {
732311Sseb 		val = mac_stat_get(dlp->dl_mh, i_dls_si[i].msi_stat);
740Sstevel@tonic-gate 
752311Sseb 		switch (i_dls_si[i].msi_type) {
760Sstevel@tonic-gate 		case KSTAT_DATA_UINT64:
770Sstevel@tonic-gate 			knp->value.ui64 = val;
780Sstevel@tonic-gate 			break;
790Sstevel@tonic-gate 		case KSTAT_DATA_UINT32:
800Sstevel@tonic-gate 			knp->value.ui32 = (uint32_t)val;
810Sstevel@tonic-gate 			break;
820Sstevel@tonic-gate 		default:
830Sstevel@tonic-gate 			ASSERT(B_FALSE);
840Sstevel@tonic-gate 		}
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 		knp++;
870Sstevel@tonic-gate 	}
880Sstevel@tonic-gate 
895895Syz147064 	/*
905895Syz147064 	 * Ethernet specific kstat "link_duplex"
915895Syz147064 	 */
925895Syz147064 	if (dlp->dl_mip->mi_nativemedia != DL_ETHER) {
935895Syz147064 		knp->value.ui32 = LINK_DUPLEX_UNKNOWN;
945895Syz147064 	} else {
955895Syz147064 		val = mac_stat_get(dlp->dl_mh, ETHER_STAT_LINK_DUPLEX);
965895Syz147064 		knp->value.ui32 = (uint32_t)val;
975895Syz147064 	}
985895Syz147064 	knp++;
990Sstevel@tonic-gate 	knp->value.ui32 = dlp->dl_unknowns;
1000Sstevel@tonic-gate 
1010Sstevel@tonic-gate 	return (0);
1020Sstevel@tonic-gate }
1030Sstevel@tonic-gate 
1045895Syz147064 int
dls_stat_create(const char * module,int instance,const char * name,zoneid_t zoneid,int (* update)(struct kstat *,int),void * private,kstat_t ** kspp)1055895Syz147064 dls_stat_create(const char *module, int instance, const char *name,
106*10616SSebastien.Roy@Sun.COM     zoneid_t zoneid, int (*update)(struct kstat *, int), void *private,
107*10616SSebastien.Roy@Sun.COM     kstat_t **kspp)
1080Sstevel@tonic-gate {
1095895Syz147064 	kstat_t		*ksp;
1105895Syz147064 	kstat_named_t	*knp;
1115895Syz147064 	uint_t		i;
1120Sstevel@tonic-gate 
113*10616SSebastien.Roy@Sun.COM 	if ((ksp = kstat_create_zone(module, instance, name, "net",
114*10616SSebastien.Roy@Sun.COM 	    KSTAT_TYPE_NAMED, STAT_INFO_COUNT + 2, 0, zoneid)) == NULL) {
1155895Syz147064 		return (EINVAL);
1165895Syz147064 	}
1170Sstevel@tonic-gate 
1185895Syz147064 	ksp->ks_update = update;
1195895Syz147064 	ksp->ks_private = private;
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	knp = (kstat_named_t *)ksp->ks_data;
1220Sstevel@tonic-gate 	for (i = 0; i < STAT_INFO_COUNT; i++) {
1232311Sseb 		kstat_named_init(knp, i_dls_si[i].msi_name,
1242311Sseb 		    i_dls_si[i].msi_type);
1250Sstevel@tonic-gate 		knp++;
1260Sstevel@tonic-gate 	}
1270Sstevel@tonic-gate 
1285895Syz147064 	kstat_named_init(knp++, "link_duplex", KSTAT_DATA_UINT32);
1290Sstevel@tonic-gate 	kstat_named_init(knp, "unknowns", KSTAT_DATA_UINT32);
1300Sstevel@tonic-gate 	kstat_install(ksp);
1315895Syz147064 	*kspp = ksp;
1325895Syz147064 	return (0);
1335895Syz147064 }
134