2 .\" This file and its contents are supplied under the terms of the
3 .\" Common Development and Distribution License ("CDDL"), version 1.0.
4 .\" You may only use this file in accordance with the terms of version
7 .\" A full copy of the text of the CDDL should have accompanied this
8 .\" source. A copy of the CDDL is also available via the Internet at
9 .\" http://www.illumos.org/license/CDDL.
12 .\" Copyright 2016 Joyent, Inc.
19 .Nd get device statistics information
21 .In sys/mac_provider.h
27 .Fa "uint64_t *stat_value"
34 A pointer to the driver's private data that was passed in via the
42 The numeric identifier of a statistic.
44 A pointer to a 64-bit unsigned value in which the device driver should
50 entry point is used to get statistics from the device driver.
51 Statistics are stored as monotonic values.
52 They should only ever increase over the lifetime of a device, resetting only as
53 part of the instance of a device attaching and detaching.
54 When hardware has values that may overflow, it is up to the device driver to
55 store them as a 64-bit quantity that does not overflow in its soft state.
57 Most device drivers will use a
59 statement, switching on the value of the statistic
61 The full list of supported statistics is available in the
66 If a device driver recognizes the value of
68 then it should store the current 64-bit unsigned integer into
70 If the device driver does not support the statistic or does not
71 recognize the requested statistic, then it should not set anything in
76 The device driver can obtain access to its soft state through the
79 It should be cast to the appropriate structure.
80 The device driver should employ any necessary locking to access the statistic
81 members of its soft state to ensure that the data is properly serialized.
83 Upon successful completion, the device driver should fill in
87 Otherwise it should return a non-zero error number to indicate an error
90 The following example shows how a driver might structure its
94 #include <sys/mac_provider.h>
95 #include <sys/mac_ether.h>
98 * Note, this example merely shows the structure of the function. For
99 * the purpose of this example, we assume that we have a device which
100 * has members that indicate its stats and that it has a lock which is
101 * used to serialize access to this data.
105 example_m_getstat(void *arg, uint_t stat, uint64_t *val)
109 mutex_enter(&ep->ep_lock);
111 case MAC_STAT_RBYTES:
112 *val = ep->ep_stats.eps_rbytes;
114 case MAC_STAT_OBYTES:
115 *val = ep->ep_stats.eps_obytes;
117 case MAC_STAT_IPACKETS:
118 *val = ep->ep_stats.eps_ipackets;
120 case MAC_STAT_OPACKETS:
121 *val = ep->ep_stats.eps_opackets;
125 * Note, there are many more stats that should be checked and
126 * filled in if supported. You should use one case statement for
131 mutex_exit(&ep->ep_lock);
134 mutex_exit(&ep->ep_lock);
140 The device driver may return one of the following errors.
141 While this list is not intended to be exhaustive, it is recommended to use one
142 of these if possible.
145 The specified statistic is unknown, unsupported, or unimplemented.
147 A transport or DMA FM related error occurred while trying to sync data
150 The device is not currently in a state where it can currently service
155 .Xr mac_register 9F ,