xref: /illumos-gate/usr/src/uts/common/io/dls/dls_mod.c (revision 06e1a714)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Data-Link Services Module
31  */
32 
33 #include	<sys/types.h>
34 #include	<sys/modctl.h>
35 #include	<sys/mac.h>
36 
37 #include	<sys/dls.h>
38 #include	<sys/dls_impl.h>
39 
40 static struct modlmisc		i_dls_modlmisc = {
41 	&mod_miscops,
42 	DLS_INFO
43 };
44 
45 static struct modlinkage	i_dls_modlinkage = {
46 	MODREV_1,
47 	&i_dls_modlmisc,
48 	NULL
49 };
50 
51 /*
52  * Module initialization functions.
53  */
54 
55 static void
56 i_dls_mod_init(void)
57 {
58 	dls_init();
59 	dls_vlan_init();
60 	dls_link_init();
61 }
62 
63 static int
64 i_dls_mod_fini(void)
65 {
66 	int	err;
67 
68 	if ((err = dls_link_fini()) != 0)
69 		return (err);
70 
71 	err = dls_vlan_fini();
72 	ASSERT(err == 0);
73 
74 	err = dls_fini();
75 	ASSERT(err == 0);
76 
77 	return (0);
78 }
79 
80 /*
81  * modlinkage functions.
82  */
83 
84 int
85 _init(void)
86 {
87 	int	err;
88 
89 	i_dls_mod_init();
90 
91 	if ((err = mod_install(&i_dls_modlinkage)) != 0) {
92 		(void) i_dls_mod_fini();
93 		return (err);
94 	}
95 
96 #ifdef	DEBUG
97 	cmn_err(CE_NOTE, "!%s loaded", DLS_INFO);
98 #endif	/* DEBUG */
99 
100 	return (0);
101 }
102 
103 int
104 _fini(void)
105 {
106 	int	err;
107 
108 	if ((err = i_dls_mod_fini()) != 0)
109 		return (err);
110 
111 	if ((err = mod_remove(&i_dls_modlinkage)) != 0)
112 		return (err);
113 
114 #ifdef	DEBUG
115 	cmn_err(CE_NOTE, "!%s unloaded", DLS_INFO);
116 #endif	/* DEBUG */
117 
118 	return (0);
119 }
120 
121 int
122 _info(struct modinfo *modinfop)
123 {
124 	return (mod_info(&i_dls_modlinkage, modinfop));
125 }
126