1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
.\"
.\" This file and its contents are supplied under the terms of the
.\" Common Development and Distribution License ("CDDL"), version 1.0.
.\" You may only use this file in accordance with the terms of version
.\" 1.0 of the CDDL.
.\"
.\" A full copy of the text of the CDDL should have accompanied this
.\" source. A copy of the CDDL is also available via the Internet at
.\" http://www.illumos.org/license/CDDL.
.\"
.\"
.\" Copyright 2016 Joyent, Inc.
.\"
.Dd May 31, 2016
.Dt MAC_INIT_OPS 9F
.Os
.Sh NAME
.Nm mac_init_ops ,
.Nm mac_fini_ops
.Nd initialize and finalize driver support for the MAC framework
.Sh SYNOPSIS
.In sys/mac_provider.h
.Ft void
.Fo mac_init_ops
.Fa "struct dev_ops *ops"
.Fa "const char *name"
.Fc
.Ft void
.Fo mac_fini_ops
.Fa "struct dev_ops *ops"
.Fc
.Sh INTERFACE LEVEL
illumos DDI specific
.Sh PARAMETERS
.Bl -tag -width Ds
.It Fa ops
A pointer to the driver's
.Xr dev_ops 9S
structure.
.It Fa name
A pointer to a null-terminated string of ASCII characters that contains
the name of the driver.
.El
.Sh DESCRIPTION
The
.Fn mac_init_ops
and
.Fn mac_fini_ops
functions are used to initialize and finalize support for a device
driver that implements the
.Xr mac 9E
networking device framework.
.Pp
The
.Fn mac_init_ops
function should be called during the driver's
.Xr _init 9E
entry point.
As described in more detail in the
.Sx Initializing MAC Support
section of
.Xr mac 9E ,
this must be called before the driver calls
.Xr mod_install 9F .
If this is not done, then the call to
.Xr mac_register 9F
will fail.
.Pp
When in the driver's
.Xr _fini 9E
entry point, after the call to
.Xr mod_remove 9F
has succeeded, then the driver must call the
.Fn mac_fini_ops
function to finalize support and finish releasing any resources.
If the call to
.Xr mod_remove 9F
fails, then the device driver should not call
.Fn mac_fini_ops
and should fail the call to
.Xr _fini 9E .
.Pp
In addition, if the call to
.Xr mod_install 9F
in the driver's
.Xr _init 9E
entry point fails, then the driver should also call
.Fn mac_fini_ops .
See the example below for how this should be structured.
.Sh CONTEXT
The
.Fn mac_init_ops
function should only ever be called from the context of a driver's
.Xr _init 9E
entry point.
.Pp
The
.Fn mac_fini_ops
function should only ever be called from the context of a driver's
.Xr _init 9E
or
.Xr _fini 9E
entry point.
.Sh RETURN VALUES
The
.Fn mac_init_ops
and
.Fn mac_fini_ops
functions will always succeed.
They do not have any kind of return value.
.Sh EXAMPLES
The following example shows how a driver would call
.Fn mac_init_ops
and
.Fn mac_fini_ops
correctly in the
.Xr _init 9E
and
.Xr _fini 9E
entry points of a driver.
.Bd -literal
#include <sys/modctl.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/mac_provider.h>
/*
* When using this, replace mydrv with the name of the actual device
* driver. In addition, the mydrv_ prefix that is used should be
* replaced with the name of the device driver
*/
#define MYDRV_NAME "mydrv"
/*
* The following dev_ops structure would need to be filled in by a
* proper device driver.
*/
static struct dev_ops mydrv_dev_ops;
static struct modldrv mydrv_modldrv = {
&mod_driverops,
MYDRV_NAME,
&mydrv_dev_ops
};
static struct modlinkage mydrv_modlinkage = {
MODREV_1,
&mydrv_modldrv,
NULL
};
int
_init(void)
{
int ret;
/* Perform other needed initialization */
mac_init_ops(&mydrv_devops, MYDRV_NAME);
ret = mod_install(&mydrv_modlinkage);
if (ret != DDI_SUCCESS) {
mac_fini_ops(&mydrv_devops);
/* Perform other needed finalization */
}
return (ret);
}
int
_info(struct modinfo *modinfop)
{
return (mod_info(&mydrv_modlinkage, modinfo));
}
int
_fini(void)
{
int ret;
ret = mod_remove(&mydrv_modlinkage);
if (ret == DDI_SUCCESS) {
mac_fini_ops(&mydrv_devops);
/* Perform other needed finalization */
}
return (ret);
}
.Ed
.Sh SEE ALSO
.Xr _fini 9E ,
.Xr _init 9E ,
.Xr mac 9E ,
.Xr mod_install 9F ,
.Xr mod_remove 9F ,
.Xr dev_ops 9S
|