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]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #include <sys/types.h>
28 #include <sys/errno.h>
29 #include <sys/param.h>
30 #include <sys/stream.h>
31 #include <sys/strsubr.h>
33 #include <sys/ksynch.h>
35 #include <sys/vgen_stats.h>
38 * A set of common kstat statistics related functions that are
39 * used by both vnet and vsw drivers to maintain the statistics specific
44 * Setup kstats for the LDC statistics.
45 * NOTE: the synchronization for the statistics is the
46 * responsibility of the caller.
49 vgen_setup_kstats(char *ks_mod
, int instance
,
50 char *ks_name
, vgen_stats_t
*statsp
)
56 size
= sizeof (vgen_kstats_t
) / sizeof (kstat_named_t
);
57 ksp
= kstat_create(ks_mod
, instance
, ks_name
, "net", KSTAT_TYPE_NAMED
,
63 ldckp
= (vgen_kstats_t
*)ksp
->ks_data
;
64 kstat_named_init(&ldckp
->ipackets
, "ipackets",
66 kstat_named_init(&ldckp
->ipackets64
, "ipackets64",
67 KSTAT_DATA_ULONGLONG
);
68 kstat_named_init(&ldckp
->ierrors
, "ierrors",
70 kstat_named_init(&ldckp
->opackets
, "opackets",
72 kstat_named_init(&ldckp
->opackets64
, "opackets64",
73 KSTAT_DATA_ULONGLONG
);
74 kstat_named_init(&ldckp
->oerrors
, "oerrors",
78 /* MIB II kstat variables */
79 kstat_named_init(&ldckp
->rbytes
, "rbytes",
81 kstat_named_init(&ldckp
->rbytes64
, "rbytes64",
82 KSTAT_DATA_ULONGLONG
);
83 kstat_named_init(&ldckp
->obytes
, "obytes",
85 kstat_named_init(&ldckp
->obytes64
, "obytes64",
86 KSTAT_DATA_ULONGLONG
);
87 kstat_named_init(&ldckp
->multircv
, "multircv",
89 kstat_named_init(&ldckp
->multixmt
, "multixmt",
91 kstat_named_init(&ldckp
->brdcstrcv
, "brdcstrcv",
93 kstat_named_init(&ldckp
->brdcstxmt
, "brdcstxmt",
95 kstat_named_init(&ldckp
->norcvbuf
, "norcvbuf",
97 kstat_named_init(&ldckp
->noxmtbuf
, "noxmtbuf",
101 kstat_named_init(&ldckp
->tx_no_desc
, "tx_no_desc",
103 kstat_named_init(&ldckp
->tx_qfull
, "tx_qfull",
105 kstat_named_init(&ldckp
->tx_pri_fail
, "tx_pri_fail",
107 kstat_named_init(&ldckp
->tx_pri_packets
, "tx_pri_packets",
108 KSTAT_DATA_ULONGLONG
);
109 kstat_named_init(&ldckp
->tx_pri_bytes
, "tx_pri_bytes",
110 KSTAT_DATA_ULONGLONG
);
113 kstat_named_init(&ldckp
->rx_allocb_fail
, "rx_allocb_fail",
115 kstat_named_init(&ldckp
->rx_vio_allocb_fail
, "rx_vio_allocb_fail",
117 kstat_named_init(&ldckp
->rx_lost_pkts
, "rx_lost_pkts",
119 kstat_named_init(&ldckp
->rx_pri_fail
, "rx_pri_fail",
121 kstat_named_init(&ldckp
->rx_pri_packets
, "rx_pri_packets",
122 KSTAT_DATA_ULONGLONG
);
123 kstat_named_init(&ldckp
->rx_pri_bytes
, "rx_pri_bytes",
124 KSTAT_DATA_ULONGLONG
);
126 /* Interrupt stats */
127 kstat_named_init(&ldckp
->callbacks
, "callbacks",
129 kstat_named_init(&ldckp
->dring_data_msgs_sent
, "dring_data_msgs_sent",
131 kstat_named_init(&ldckp
->dring_data_acks_rcvd
, "dring_data_acks_rcvd",
133 kstat_named_init(&ldckp
->dring_stopped_acks_rcvd
,
134 "dring_stopped_acks_rcvd", KSTAT_DATA_ULONG
);
135 kstat_named_init(&ldckp
->dring_data_msgs_rcvd
, "dring_data_msgs_rcvd",
137 kstat_named_init(&ldckp
->dring_data_acks_sent
, "dring_data_acks_sent",
139 kstat_named_init(&ldckp
->dring_stopped_acks_sent
,
140 "dring_stopped_acks_sent", KSTAT_DATA_ULONG
);
141 kstat_named_init(&ldckp
->dring_mode
, "dring_mode", KSTAT_DATA_ULONG
);
143 ksp
->ks_update
= vgen_kstat_update
;
144 ksp
->ks_private
= (void *)statsp
;
153 vgen_destroy_kstats(kstat_t
*ksp
)
163 vgen_kstat_update(kstat_t
*ksp
, int rw
)
165 vgen_stats_t
*statsp
;
166 vgen_kstats_t
*ldckp
;
168 statsp
= (vgen_stats_t
*)ksp
->ks_private
;
169 ldckp
= (vgen_kstats_t
*)ksp
->ks_data
;
171 if (rw
== KSTAT_READ
) {
172 ldckp
->ipackets
.value
.ul
= (uint32_t)statsp
->ipackets
+
173 (uint32_t)statsp
->rx_pri_packets
;
174 ldckp
->ipackets64
.value
.ull
= statsp
->ipackets
+
175 statsp
->rx_pri_packets
;
176 ldckp
->ierrors
.value
.ul
= statsp
->ierrors
;
177 ldckp
->opackets
.value
.ul
= (uint32_t)statsp
->opackets
+
178 (uint32_t)statsp
->tx_pri_packets
;
179 ldckp
->opackets64
.value
.ull
= statsp
->opackets
+
180 statsp
->tx_pri_packets
;
181 ldckp
->oerrors
.value
.ul
= statsp
->oerrors
;
184 * MIB II kstat variables
186 ldckp
->rbytes
.value
.ul
= (uint32_t)statsp
->rbytes
+
187 (uint32_t)statsp
->rx_pri_bytes
;
188 ldckp
->rbytes64
.value
.ull
= statsp
->rbytes
+
189 statsp
->rx_pri_bytes
;
190 ldckp
->obytes
.value
.ul
= (uint32_t)statsp
->obytes
+
191 (uint32_t)statsp
->tx_pri_bytes
;
192 ldckp
->obytes64
.value
.ull
= statsp
->obytes
+
193 statsp
->tx_pri_bytes
;
194 ldckp
->multircv
.value
.ul
= statsp
->multircv
;
195 ldckp
->multixmt
.value
.ul
= statsp
->multixmt
;
196 ldckp
->brdcstrcv
.value
.ul
= statsp
->brdcstrcv
;
197 ldckp
->brdcstxmt
.value
.ul
= statsp
->brdcstxmt
;
198 ldckp
->norcvbuf
.value
.ul
= statsp
->norcvbuf
;
199 ldckp
->noxmtbuf
.value
.ul
= statsp
->noxmtbuf
;
201 ldckp
->tx_no_desc
.value
.ul
= statsp
->tx_no_desc
;
202 ldckp
->tx_qfull
.value
.ul
= statsp
->tx_qfull
;
203 ldckp
->tx_pri_fail
.value
.ul
= statsp
->tx_pri_fail
;
204 ldckp
->tx_pri_packets
.value
.ull
= statsp
->tx_pri_packets
;
205 ldckp
->tx_pri_bytes
.value
.ull
= statsp
->tx_pri_bytes
;
207 ldckp
->rx_allocb_fail
.value
.ul
= statsp
->rx_allocb_fail
;
208 ldckp
->rx_vio_allocb_fail
.value
.ul
= statsp
->rx_vio_allocb_fail
;
209 ldckp
->rx_lost_pkts
.value
.ul
= statsp
->rx_lost_pkts
;
210 ldckp
->rx_pri_fail
.value
.ul
= statsp
->rx_pri_fail
;
211 ldckp
->rx_pri_packets
.value
.ull
= statsp
->rx_pri_packets
;
212 ldckp
->rx_pri_bytes
.value
.ull
= statsp
->rx_pri_bytes
;
214 ldckp
->callbacks
.value
.ul
= statsp
->callbacks
;
216 ldckp
->dring_data_msgs_sent
.value
.ul
=
217 statsp
->dring_data_msgs_sent
;
218 ldckp
->dring_data_acks_rcvd
.value
.ul
=
219 statsp
->dring_data_acks_rcvd
;
220 ldckp
->dring_stopped_acks_rcvd
.value
.ul
=
221 statsp
->dring_stopped_acks_rcvd
;
222 ldckp
->dring_data_msgs_rcvd
.value
.ul
=
223 statsp
->dring_data_msgs_rcvd
;
224 ldckp
->dring_data_acks_sent
.value
.ul
=
225 statsp
->dring_data_acks_sent
;
226 ldckp
->dring_stopped_acks_sent
.value
.ul
=
227 statsp
->dring_stopped_acks_sent
;
228 ldckp
->dring_mode
.value
.ul
= statsp
->dring_mode
;
230 statsp
->ipackets
= ldckp
->ipackets64
.value
.ull
;
231 statsp
->ierrors
= ldckp
->ierrors
.value
.ul
;
232 statsp
->opackets
= ldckp
->opackets64
.value
.ull
;
233 statsp
->oerrors
= ldckp
->oerrors
.value
.ul
;
236 * MIB II kstat variables
238 statsp
->rbytes
= ldckp
->rbytes64
.value
.ull
;
239 statsp
->obytes
= ldckp
->obytes64
.value
.ull
;
240 statsp
->multircv
= ldckp
->multircv
.value
.ul
;
241 statsp
->multixmt
= ldckp
->multixmt
.value
.ul
;
242 statsp
->brdcstrcv
= ldckp
->brdcstrcv
.value
.ul
;
243 statsp
->brdcstxmt
= ldckp
->brdcstxmt
.value
.ul
;
244 statsp
->norcvbuf
= ldckp
->norcvbuf
.value
.ul
;
245 statsp
->noxmtbuf
= ldckp
->noxmtbuf
.value
.ul
;
247 statsp
->tx_no_desc
= ldckp
->tx_no_desc
.value
.ul
;
248 statsp
->tx_qfull
= ldckp
->tx_qfull
.value
.ul
;
249 statsp
->tx_pri_fail
= ldckp
->tx_pri_fail
.value
.ul
;
250 statsp
->tx_pri_packets
= ldckp
->tx_pri_packets
.value
.ull
;
251 statsp
->tx_pri_bytes
= ldckp
->tx_pri_bytes
.value
.ull
;
253 statsp
->rx_allocb_fail
= ldckp
->rx_allocb_fail
.value
.ul
;
254 statsp
->rx_vio_allocb_fail
= ldckp
->rx_vio_allocb_fail
.value
.ul
;
255 statsp
->rx_lost_pkts
= ldckp
->rx_lost_pkts
.value
.ul
;
256 statsp
->rx_pri_fail
= ldckp
->rx_pri_fail
.value
.ul
;
257 statsp
->rx_pri_packets
= ldckp
->rx_pri_packets
.value
.ull
;
258 statsp
->rx_pri_bytes
= ldckp
->rx_pri_bytes
.value
.ull
;
260 statsp
->callbacks
= ldckp
->callbacks
.value
.ul
;
261 statsp
->dring_data_msgs_sent
=
262 ldckp
->dring_data_msgs_sent
.value
.ul
;
263 statsp
->dring_data_acks_rcvd
=
264 ldckp
->dring_data_acks_rcvd
.value
.ul
;
265 statsp
->dring_stopped_acks_rcvd
=
266 ldckp
->dring_stopped_acks_rcvd
.value
.ul
;
267 statsp
->dring_data_msgs_rcvd
=
268 ldckp
->dring_data_msgs_rcvd
.value
.ul
;
269 statsp
->dring_data_acks_sent
=
270 ldckp
->dring_data_acks_sent
.value
.ul
;
271 statsp
->dring_stopped_acks_sent
=
272 ldckp
->dring_stopped_acks_sent
.value
.ul
;
273 statsp
->dring_mode
= ldckp
->dring_mode
.value
.ul
;