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.
20 .Nd register and unregister a device driver from the MAC framework
22 .In sys/mac_provider.h
25 .Fa "mac_register_t *mregp"
26 .Fa "mac_handle_t *mhp"
39 structure allocated by calling
41 and filled in by the device driver.
43 A pointer to a driver-backed handle to the MAC framework.
45 The driver-backed handle to the MAC framework.
50 function is used to register an instance of a device driver with the
53 Upon successfully calling the
55 function, the device will start having its
58 The device driver should call this function during it's
60 entry point after the device has been configured and is set up.
61 For a more detailed explanation of the exact steps that the device driver
62 should take and where in the sequence of a driver's
64 entry point this function should be called, see the
65 .Sx Registering with MAC
69 The driver should provide a pointer to a
71 structure as the second argument to the
74 This handle will be used when the device driver needs to interact with the
75 framework in various ways throughout its life.
76 It is also where the driver gets the
78 argument for calling the
81 It is recommended that the device driver keep the handle around in its soft
82 state structure for a given instance.
86 function fails, the device driver should unwind its
88 entry point, tear down everything that it initialized, and ultimately
89 return an error from its
95 routine fails for some reason after the call to the
97 function has succeeded, then the driver should call the
99 function as part of unwinding all of its state.
101 When a driver is in its
103 entry point, it should call the
105 function immediately after draining any of its transmit and receive
106 resources that might have been given to the rest of the operating system
112 for more information.
113 This should be done before the driver does any tearing down.
117 This may happen because the networking stack is still using the device.
118 In such a case, the driver should fail the call to
125 function is generally only called from a driver's
130 function is generally only called from a driver's
135 However, both functions may be called from either
141 Upon successful completion, the
145 functions both return
147 Otherwise, they return an error number.
149 The following example shows how a device driver might call the
153 #include <sys/mac_provider.h>
154 #include <sys/mac_ether.h>
157 * The call to mac_register(9F) generally comes from the context of
158 * attach(9E). This function encapsulates setting up and initializing
159 * the mac_register_t structure and should be assumed to be called from
162 * The exact set of callbacks and private properties will vary based
166 static char *example_priv_props[] = {
172 static mac_callbacks_t example_m_callbacks = {
173 .mc_callbacsk = MC_GETCAPAB | MC_SETPROP | MC_GETPROP | MC_PROPINFO |
175 .mc_start = example_m_start,
176 .mc_stop = example_m_stop,
177 .mc_setpromisc = example_m_setpromisc,
178 .mc_multicst = example_m_multicst,
179 .mc_unicst = example_m_unicst,
180 .mc_tx = example_m_tx,
181 .mc_ioctl = example_m_ioctl,
182 .mc_getcapab = example_m_getcapab,
183 .mc_getprop = example_m_getprop,
184 .mc_setprop = example_m_setprop,
185 .mc_propinfo = example_m_propinfo
189 example_register_mac(example_t *ep)
194 mac = mac_alloc(MAC_VERSION);
198 mac->m_type_indent = MAC_PLUGIN_IDENT_ETHER;
200 mac->m_dip = ep->ep_dev_info;
201 mac->m_src_addr = ep->ep_mac_addr;
202 mac->m_callbacks = &example_m_callbacks;
204 mac->m_max_sdu = ep->ep_sdu;
205 mac->m_margin = VLAN_TAGSZ;
206 mac->m_priv_props = exmple_priv_props;
208 status = mac_register(mac, &ep->ep_mac_hdl);
211 return (status == 0);
217 function may fail if:
220 A driver with the same name and instance already exists.
222 There was something invalid with the device's registration information.
223 Some of the following reasons may apply, this list is not exhaustive:
228 function was not called.
230 The specified mac plugin does not exist.
232 An invalid minor number was used.
234 The default unicast source address was incorrect.
236 The plugin specific private data was incorrect or missing.
238 Plugin specific data was provided when none is required.
240 Required callback functions are not specified.
242 The system was unable to properly create minor nodes.
247 framework was unable to allocate a minor number for the device as they
248 have all been exhausted.
253 function will fail if:
256 The device is still in use.
258 The flow table is not empty.
261 Note the set of errors for both the
265 functions are not set in stone and may be expanded in future revisions.
266 In general, all errors should be handled by the device driver in similar
267 ways for these functions.
273 .Xr mac_init_ops 9F ,
274 .Xr mac_callbacks 9S ,