4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
27 * Data-Link Services Module
30 #include <sys/dld_impl.h>
31 #include <sys/mac_ether.h>
33 static mac_stat_info_t i_dls_si
[] = {
34 { MAC_STAT_IFSPEED
, "ifspeed", KSTAT_DATA_UINT64
, 0 },
35 { MAC_STAT_MULTIRCV
, "multircv", KSTAT_DATA_UINT32
, 0 },
36 { MAC_STAT_BRDCSTRCV
, "brdcstrcv", KSTAT_DATA_UINT32
, 0 },
37 { MAC_STAT_MULTIXMT
, "multixmt", KSTAT_DATA_UINT32
, 0 },
38 { MAC_STAT_BRDCSTXMT
, "brdcstxmt", KSTAT_DATA_UINT32
, 0 },
39 { MAC_STAT_NORCVBUF
, "norcvbuf", KSTAT_DATA_UINT32
, 0 },
40 { MAC_STAT_IERRORS
, "ierrors", KSTAT_DATA_UINT32
, 0 },
41 { MAC_STAT_NOXMTBUF
, "noxmtbuf", KSTAT_DATA_UINT32
, 0 },
42 { MAC_STAT_OERRORS
, "oerrors", KSTAT_DATA_UINT32
, 0 },
43 { MAC_STAT_COLLISIONS
, "collisions", KSTAT_DATA_UINT32
, 0 },
44 { MAC_STAT_RBYTES
, "rbytes", KSTAT_DATA_UINT32
, 0 },
45 { MAC_STAT_IPACKETS
, "ipackets", KSTAT_DATA_UINT32
, 0 },
46 { MAC_STAT_OBYTES
, "obytes", KSTAT_DATA_UINT32
, 0 },
47 { MAC_STAT_OPACKETS
, "opackets", KSTAT_DATA_UINT32
, 0 },
48 { MAC_STAT_RBYTES
, "rbytes64", KSTAT_DATA_UINT64
, 0 },
49 { MAC_STAT_IPACKETS
, "ipackets64", KSTAT_DATA_UINT64
, 0 },
50 { MAC_STAT_OBYTES
, "obytes64", KSTAT_DATA_UINT64
, 0 },
51 { MAC_STAT_OPACKETS
, "opackets64", KSTAT_DATA_UINT64
, 0 },
52 { MAC_STAT_LINK_STATE
, "link_state", KSTAT_DATA_UINT32
,
53 (uint64_t)LINK_STATE_UNKNOWN
}
56 #define STAT_INFO_COUNT (sizeof (i_dls_si) / sizeof (i_dls_si[0]))
62 dls_stat_update(kstat_t
*ksp
, dls_link_t
*dlp
, int rw
)
71 knp
= (kstat_named_t
*)ksp
->ks_data
;
72 for (i
= 0; i
< STAT_INFO_COUNT
; i
++) {
73 val
= mac_stat_get(dlp
->dl_mh
, i_dls_si
[i
].msi_stat
);
75 switch (i_dls_si
[i
].msi_type
) {
76 case KSTAT_DATA_UINT64
:
77 knp
->value
.ui64
= val
;
79 case KSTAT_DATA_UINT32
:
80 knp
->value
.ui32
= (uint32_t)val
;
90 * Ethernet specific kstat "link_duplex"
92 if (dlp
->dl_mip
->mi_nativemedia
!= DL_ETHER
) {
93 knp
->value
.ui32
= LINK_DUPLEX_UNKNOWN
;
95 val
= mac_stat_get(dlp
->dl_mh
, ETHER_STAT_LINK_DUPLEX
);
96 knp
->value
.ui32
= (uint32_t)val
;
99 knp
->value
.ui32
= dlp
->dl_unknowns
;
105 dls_stat_create(const char *module
, int instance
, const char *name
,
106 zoneid_t zoneid
, int (*update
)(struct kstat
*, int), void *private,
113 if ((ksp
= kstat_create_zone(module
, instance
, name
, "net",
114 KSTAT_TYPE_NAMED
, STAT_INFO_COUNT
+ 2, 0, zoneid
)) == NULL
) {
118 ksp
->ks_update
= update
;
119 ksp
->ks_private
= private;
121 knp
= (kstat_named_t
*)ksp
->ks_data
;
122 for (i
= 0; i
< STAT_INFO_COUNT
; i
++) {
123 kstat_named_init(knp
, i_dls_si
[i
].msi_name
,
124 i_dls_si
[i
].msi_type
);
128 kstat_named_init(knp
++, "link_duplex", KSTAT_DATA_UINT32
);
129 kstat_named_init(knp
, "unknowns", KSTAT_DATA_UINT32
);