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