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 properties
21 .In sys/mac_provider.h
25 .Fa "const char *pr_name"
26 .Fa "mac_prop_id_t pr_num"
27 .Fa "uint_t pr_valsize"
35 A pointer to the driver's private data that was passed in via the
43 A null-terminated string that contains the name of the property.
45 A constant that is used to identify the property.
47 A value that indicates the size in bytes of
52 byte buffer that can store the property.
57 entry point is used to obtain the value of a given device's property and
63 entry point is called, the driver needs to first identify the property.
64 The set of possible properties and their meaning is listed in the
68 It should identify the property based on the value of
70 Most drivers will use a
72 statement and for any property that it supports it should then check if
75 is sufficient for the property, comparing it to the minimum size
76 listed for the property in
78 If it is not, then it should return an error.
79 Otherwise, it should copy the property's value into
81 When an unknown or unsupported
82 property is encountered, generally the
84 case of the switch statement, the device driver should return an error.
88 indicates that this is a device driver specific private property.
89 The device driver must then look at the value of the
93 on it, comparing it to each of its private (bounded-size) properties to
94 identify which one it is.
96 At this time, private properties are limited to being string based properties.
97 If other types of property values are used, they will not be rendered
102 driver can access its device soft state by casting the
104 pointer to the appropriate structure.
105 As this may be called while other operations are ongoing, the device driver
106 should employ the appropriate locking while reading the properties.
110 function is generally called from
114 Upon successful completion, the device driver should have copied the
115 value of the property into
119 Otherwise, a positive error should be returned to indicate failure.
121 The following example shows how a device driver might structure its
125 #include <sys/mac_provider.h>
128 * Note, this example merely shows the structure of this function.
129 * Different devices will manage their state in different ways. Like other
130 * examples, this assumes that the device has state in a structure called
131 * example_t and that there is a lock which keeps track of that state.
133 static char *example_priv_props[] = {
140 example_m_getprop_private(example_t *ep, const char *pr_name, uint_t pr_valsize,
145 ASSERT(MUTEX_HELD(&ep->ep_lock));
146 if (strcmp(pr_name, example_priv_props[0] == 0) {
148 } else if (strcmp(pr_name, exampe_priv_props[1] == 0) {
155 * Due to issues in the GLDv3, these must be returned as string
158 if (snprintf(pr_val, pr_valsize, "%d", val) >= pr_valsize)
165 example_m_getprop(void *arg, const char *pr_name, mac_prop_id_t pr_num,
166 uint_t pr_valsize, void *pr_val)
172 mutex_enter(&ep->ep_lock);
175 * This only handles a subset of the properties that exist on the
176 * system. A proper driver will need to handle more. See mac(9E) for a
177 * full property list.
180 case MAC_PROP_DUPLEX:
181 if (pr_valsize < sizeof (link_duplex_t)) {
185 bcopy(ep->ep_link_duplex, pr_val, sizeof (link_duplex_t));
187 if (pr_valsize < sizeof (uint64_t)) {
192 * The link speed is stored in Mbits/s in this driver and is
193 * expected in bits/s.
195 speed = ep->ep_link_speed * 1000000ULL;
196 bcopy(&speed, pr_val, sizeof (speed));
199 if (pr_valsize < sizeof (uint32_t)) {
203 bcopy(&ep->ep_mtu, pr_val, sizeof (speed));
205 case MAC_PROP_PRIVATE:
206 ret = example_m_getprop_private(ep, pr_name, pr_valsize,
214 mutex_exit(&ep->ep_lock);
220 The device driver may return one of the following errors.
221 While this list is not intended to be exhaustive, it is recommended to use one
222 of these if possible.
225 This error should be used whenever an unknown or unsupported property is
228 This error should be used when
230 is smaller than the required size for a given value.
234 .Xr mac_register 9F ,