xref: /illumos-gate/usr/src/uts/common/io/dls/dls_stat.c (revision ba2e4443695ee6a6f420a35cd4fc3d3346d22932)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*ba2e4443Sseb  * Common Development and Distribution License (the "License").
6*ba2e4443Sseb  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*ba2e4443Sseb  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * Data-Link Services Module
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
347c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
357c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
367c478bd9Sstevel@tonic-gate #include <sys/vlan.h>
377c478bd9Sstevel@tonic-gate #include <sys/mac.h>
387c478bd9Sstevel@tonic-gate #include <sys/ctype.h>
397c478bd9Sstevel@tonic-gate #include <sys/dls.h>
407c478bd9Sstevel@tonic-gate #include <sys/dls_impl.h>
417c478bd9Sstevel@tonic-gate 
42*ba2e4443Sseb static mac_stat_info_t	i_dls_si[] = {
43*ba2e4443Sseb 	{ MAC_STAT_IFSPEED, "ifspeed", KSTAT_DATA_UINT64, 0 },
44*ba2e4443Sseb 	{ MAC_STAT_MULTIRCV, "multircv", KSTAT_DATA_UINT32, 0 },
45*ba2e4443Sseb 	{ MAC_STAT_BRDCSTRCV, "brdcstrcv", KSTAT_DATA_UINT32, 0 },
46*ba2e4443Sseb 	{ MAC_STAT_MULTIXMT, "multixmt", KSTAT_DATA_UINT32, 0 },
47*ba2e4443Sseb 	{ MAC_STAT_BRDCSTXMT, "brdcstxmt", KSTAT_DATA_UINT32, 0 },
48*ba2e4443Sseb 	{ MAC_STAT_NORCVBUF, "norcvbuf", KSTAT_DATA_UINT32, 0 },
49*ba2e4443Sseb 	{ MAC_STAT_IERRORS, "ierrors", KSTAT_DATA_UINT32, 0 },
50*ba2e4443Sseb 	{ MAC_STAT_NOXMTBUF, "noxmtbuf", KSTAT_DATA_UINT32, 0 },
51*ba2e4443Sseb 	{ MAC_STAT_OERRORS, "oerrors", KSTAT_DATA_UINT32, 0 },
52*ba2e4443Sseb 	{ MAC_STAT_COLLISIONS, "collisions", KSTAT_DATA_UINT32, 0 },
53*ba2e4443Sseb 	{ MAC_STAT_RBYTES, "rbytes", KSTAT_DATA_UINT32, 0 },
54*ba2e4443Sseb 	{ MAC_STAT_IPACKETS, "ipackets", KSTAT_DATA_UINT32, 0 },
55*ba2e4443Sseb 	{ MAC_STAT_OBYTES, "obytes", KSTAT_DATA_UINT32, 0 },
56*ba2e4443Sseb 	{ MAC_STAT_OPACKETS, "opackets", KSTAT_DATA_UINT32, 0 },
57*ba2e4443Sseb 	{ MAC_STAT_RBYTES, "rbytes64", KSTAT_DATA_UINT64, 0 },
58*ba2e4443Sseb 	{ MAC_STAT_IPACKETS, "ipackets64", KSTAT_DATA_UINT64, 0 },
59*ba2e4443Sseb 	{ MAC_STAT_OBYTES, "obytes64", KSTAT_DATA_UINT64, 0 },
60*ba2e4443Sseb 	{ MAC_STAT_OPACKETS, "opackets64", KSTAT_DATA_UINT64, 0 }
617c478bd9Sstevel@tonic-gate };
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate #define	STAT_INFO_COUNT	(sizeof (i_dls_si) / sizeof (i_dls_si[0]))
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate /*
667c478bd9Sstevel@tonic-gate  * Private functions.
677c478bd9Sstevel@tonic-gate  */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate static int
707c478bd9Sstevel@tonic-gate i_dls_stat_update(kstat_t *ksp, int rw)
717c478bd9Sstevel@tonic-gate {
727c478bd9Sstevel@tonic-gate 	dls_vlan_t	*dvp = ksp->ks_private;
737c478bd9Sstevel@tonic-gate 	dls_link_t	*dlp = dvp->dv_dlp;
747c478bd9Sstevel@tonic-gate 	kstat_named_t	*knp;
757c478bd9Sstevel@tonic-gate 	uint_t		i;
767c478bd9Sstevel@tonic-gate 	uint64_t	val;
777c478bd9Sstevel@tonic-gate 	int		err;
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	if (rw != KSTAT_READ)
807c478bd9Sstevel@tonic-gate 		return (EACCES);
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate 	if ((err = dls_mac_hold(dlp)) != 0)
837c478bd9Sstevel@tonic-gate 		return (err);
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	knp = (kstat_named_t *)ksp->ks_data;
867c478bd9Sstevel@tonic-gate 	for (i = 0; i < STAT_INFO_COUNT; i++) {
87*ba2e4443Sseb 		val = mac_stat_get(dlp->dl_mh, i_dls_si[i].msi_stat);
887c478bd9Sstevel@tonic-gate 
89*ba2e4443Sseb 		switch (i_dls_si[i].msi_type) {
907c478bd9Sstevel@tonic-gate 		case KSTAT_DATA_UINT64:
917c478bd9Sstevel@tonic-gate 			knp->value.ui64 = val;
927c478bd9Sstevel@tonic-gate 			break;
937c478bd9Sstevel@tonic-gate 		case KSTAT_DATA_UINT32:
947c478bd9Sstevel@tonic-gate 			knp->value.ui32 = (uint32_t)val;
957c478bd9Sstevel@tonic-gate 			break;
967c478bd9Sstevel@tonic-gate 		default:
977c478bd9Sstevel@tonic-gate 			ASSERT(B_FALSE);
987c478bd9Sstevel@tonic-gate 		}
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 		knp++;
1017c478bd9Sstevel@tonic-gate 	}
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	knp->value.ui32 = dlp->dl_unknowns;
1047c478bd9Sstevel@tonic-gate 	dls_mac_rele(dlp);
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	return (0);
1077c478bd9Sstevel@tonic-gate }
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate /*
1107c478bd9Sstevel@tonic-gate  * Exported functions.
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate void
1144b46d1efSkrgopi dls_mac_stat_create(dls_vlan_t *dvp)
1157c478bd9Sstevel@tonic-gate {
1167c478bd9Sstevel@tonic-gate 	dls_link_t		*dlp = dvp->dv_dlp;
1177c478bd9Sstevel@tonic-gate 	char			module[IFNAMSIZ];
1187c478bd9Sstevel@tonic-gate 	uint_t			instance;
1197c478bd9Sstevel@tonic-gate 	kstat_t			*ksp;
1207c478bd9Sstevel@tonic-gate 	kstat_named_t		*knp;
1217c478bd9Sstevel@tonic-gate 	uint_t			i;
1227c478bd9Sstevel@tonic-gate 	int			err;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	if (dls_mac_hold(dlp) != 0)
1257c478bd9Sstevel@tonic-gate 		return;
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	err = ddi_parse(dvp->dv_name, module, &instance);
1287c478bd9Sstevel@tonic-gate 	ASSERT(err == DDI_SUCCESS);
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate 	if ((ksp = kstat_create(module, instance, NULL, "net",
131*ba2e4443Sseb 	    KSTAT_TYPE_NAMED, STAT_INFO_COUNT + 1, 0)) == NULL)
1327c478bd9Sstevel@tonic-gate 		goto done;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	ksp->ks_update = i_dls_stat_update;
1357c478bd9Sstevel@tonic-gate 	ksp->ks_private = (void *)dvp;
1367c478bd9Sstevel@tonic-gate 	dvp->dv_ksp = ksp;
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	knp = (kstat_named_t *)ksp->ks_data;
1397c478bd9Sstevel@tonic-gate 	for (i = 0; i < STAT_INFO_COUNT; i++) {
140*ba2e4443Sseb 		kstat_named_init(knp, i_dls_si[i].msi_name,
141*ba2e4443Sseb 		    i_dls_si[i].msi_type);
1427c478bd9Sstevel@tonic-gate 		knp++;
1437c478bd9Sstevel@tonic-gate 	}
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	kstat_named_init(knp, "unknowns", KSTAT_DATA_UINT32);
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	kstat_install(ksp);
1487c478bd9Sstevel@tonic-gate done:
1497c478bd9Sstevel@tonic-gate 	dls_mac_rele(dlp);
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate void
1534b46d1efSkrgopi dls_mac_stat_destroy(dls_vlan_t *dvp)
1547c478bd9Sstevel@tonic-gate {
1557c478bd9Sstevel@tonic-gate 	kstat_delete(dvp->dv_ksp);
1567c478bd9Sstevel@tonic-gate 	dvp->dv_ksp = NULL;
1577c478bd9Sstevel@tonic-gate }
158