* Remove (void) casts for discarded return values.
[dragonfly.git] / sys / netproto / atm / uni / uni_load.c
1 /*
2  *
3  * ===================================
4  * HARP  |  Host ATM Research Platform
5  * ===================================
6  *
7  *
8  * This Host ATM Research Platform ("HARP") file (the "Software") is
9  * made available by Network Computing Services, Inc. ("NetworkCS")
10  * "AS IS".  NetworkCS does not provide maintenance, improvements or
11  * support of any kind.
12  *
13  * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15  * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16  * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17  * In no event shall NetworkCS be responsible for any damages, including
18  * but not limited to consequential damages, arising from or relating to
19  * any use of the Software or related support.
20  *
21  * Copyright 1994-1998 Network Computing Services, Inc.
22  *
23  * Copies of this Software may be made, however, the above copyright
24  * notice must be reproduced on all copies.
25  *
26  *      @(#) $FreeBSD: src/sys/netatm/uni/uni_load.c,v 1.4 2000/01/17 20:49:54 mks Exp $
27  *      @(#) $DragonFly: src/sys/netproto/atm/uni/uni_load.c,v 1.8 2006/01/14 13:36:39 swildner Exp $
28  */
29
30 /*
31  * ATM Forum UNI Support
32  * ---------------------
33  *
34  * Loadable kernel module support
35  *
36  */
37
38 #ifndef ATM_UNI_MODULE
39 #include "opt_atm.h"
40 #endif
41
42 #include <netproto/atm/kern_include.h>
43
44 /*
45  * External functions
46  */
47 int             sscop_start (void);
48 int             sscop_stop (void);
49 int             sscf_uni_start (void);
50 int             sscf_uni_stop (void);
51 int             uniip_start (void);
52 int             uniip_stop (void);
53 int             unisig_start (void);
54 int             unisig_stop (void);
55
56 /*
57  * Local functions
58  */
59 static int      uni_start (void);
60 static int      uni_stop (void);
61
62
63 /*
64  * Initialize uni processing
65  * 
66  * This will be called during module loading.  We just notify all of our
67  * sub-services to initialize.
68  *
69  * Arguments:
70  *      none
71  *
72  * Returns:
73  *      0       startup was successful 
74  *      errno   startup failed - reason indicated
75  *
76  */
77 static int
78 uni_start(void)
79 {
80         int     err;
81
82         /*
83          * Verify software version
84          */
85         if (atm_version != ATM_VERSION) {
86                 log(LOG_ERR, "version mismatch: uni=%d.%d kernel=%d.%d\n",
87                         ATM_VERS_MAJ(ATM_VERSION), ATM_VERS_MIN(ATM_VERSION),
88                         ATM_VERS_MAJ(atm_version), ATM_VERS_MIN(atm_version));
89                 return (EINVAL);
90         }
91
92         /*
93          * Initialize uni sub-services
94          */
95         err = sscop_start();
96         if (err)
97                 goto done;
98
99         err = sscf_uni_start();
100         if (err)
101                 goto done;
102
103         err = unisig_start();
104         if (err)
105                 goto done;
106
107         err = uniip_start();
108         if (err)
109                 goto done;
110
111 done:
112         return (err);
113 }
114
115
116 /*
117  * Halt uni processing 
118  * 
119  * This will be called just prior to unloading the module from
120  * memory.  All sub-services will be notified of the termination.
121  *
122  * Arguments:
123  *      none
124  *
125  * Returns:
126  *      0       shutdown was successful 
127  *      errno   shutdown failed - reason indicated
128  *
129  */
130 static int
131 uni_stop(void)
132 {
133         int     err;
134
135         crit_enter();
136         /*
137          * Terminate uni sub-services
138          */
139         err = uniip_stop();
140         if (err)
141                 goto done;
142
143         err = unisig_stop();
144         if (err)
145                 goto done;
146
147         err = sscf_uni_stop();
148         if (err)
149                 goto done;
150
151         err = sscop_stop();
152         if (err)
153                 goto done;
154
155 done:
156         crit_exit();
157         return (err);
158 }
159
160
161 #ifdef ATM_UNI_MODULE
162 /*
163  *******************************************************************
164  *
165  * Loadable Module Support
166  *
167  *******************************************************************
168  */
169 static int      uni_doload (void);
170 static int      uni_dounload (void);
171
172 /*
173  * Generic module load processing
174  * 
175  * This function is called by an OS-specific function when this
176  * module is being loaded.
177  *
178  * Arguments:
179  *      none
180  *
181  * Returns:
182  *      0       load was successful 
183  *      errno   load failed - reason indicated
184  *
185  */
186 static int
187 uni_doload(void)
188 {
189         int     err = 0;
190
191         /*
192          * Start us up
193          */
194         err = uni_start();
195         if (err)
196                 /* Problems, clean up */
197                 uni_stop();
198
199         return (err);
200 }
201
202
203 /*
204  * Generic module unload processing
205  * 
206  * This function is called by an OS-specific function when this
207  * module is being unloaded.
208  *
209  * Arguments:
210  *      none
211  *
212  * Returns:
213  *      0       unload was successful 
214  *      errno   unload failed - reason indicated
215  *
216  */
217 static int
218 uni_dounload(void)
219 {
220         int     err = 0;
221
222         /*
223          * OK, try to clean up our mess
224          */
225         err = uni_stop();
226
227         return (err);
228 }
229
230 #include <sys/exec.h>
231 #include <sys/sysent.h>
232 #include <sys/lkm.h>
233
234 /*
235  * Loadable miscellaneous module description
236  */
237 MOD_MISC(uni);
238
239
240 /*
241  * Loadable module support "load" entry point
242  * 
243  * This is the routine called by the lkm driver whenever the
244  * modload(1) command is issued for this module.
245  *
246  * Arguments:
247  *      lkmtp   pointer to lkm drivers's structure
248  *      cmd     lkm command code
249  *
250  * Returns:
251  *      0       command was successful 
252  *      errno   command failed - reason indicated
253  *
254  */
255 static int
256 uni_load(struct lkm_table *lkmtp, int cmd)
257 {
258         return(uni_doload());
259 }
260
261
262 /*
263  * Loadable module support "unload" entry point
264  * 
265  * This is the routine called by the lkm driver whenever the
266  * modunload(1) command is issued for this module.
267  *
268  * Arguments:
269  *      lkmtp   pointer to lkm drivers's structure
270  *      cmd     lkm command code
271  *
272  * Returns:
273  *      0       command was successful 
274  *      errno   command failed - reason indicated
275  *
276  */
277 static int
278 uni_unload(struct lkm_table *lkmtp, int cmd)
279 {
280         return(uni_dounload());
281 }
282
283
284 /*
285  * Loadable module support entry point
286  * 
287  * This is the routine called by the lkm driver for all loadable module
288  * functions for this driver.  This routine name must be specified
289  * on the modload(1) command.  This routine will be called whenever the
290  * modload(1), modunload(1) or modstat(1) commands are issued for this
291  * module.
292  *
293  * Arguments:
294  *      lkmtp   pointer to lkm drivers's structure
295  *      cmd     lkm command code
296  *      ver     lkm version
297  *
298  * Returns:
299  *      0       command was successful 
300  *      errno   command failed - reason indicated
301  *
302  */
303 int
304 uni_mod(struct lkm_table *lkmtp, int cmd, int ver)
305 {
306         MOD_DISPATCH(uni, lkmtp, cmd, ver,
307                 uni_load, uni_unload, lkm_nullcmd);
308 }
309
310 #else   /* !ATM_UNI_MODULE */
311
312 /*
313  *******************************************************************
314  *
315  * Kernel Compiled Module Support
316  *
317  *******************************************************************
318  */
319 static void     uni_doload (void *);
320
321 SYSINIT(atmuni, SI_SUB_PROTO_END, SI_ORDER_ANY, uni_doload, NULL)
322
323 /*
324  * Kernel initialization
325  * 
326  * Arguments:
327  *      arg     Not used
328  *
329  * Returns:
330  *      none
331  *
332  */
333 static void
334 uni_doload(void *arg)
335 {
336         int     err = 0;
337
338         /*
339          * Start us up
340          */
341         err = uni_start();
342         if (err) {
343                 /* Problems, clean up */
344                 uni_stop();
345
346                 log(LOG_ERR, "ATM UNI unable to initialize (%d)!!\n", err);
347         }
348         return;
349 }
350 #endif  /* ATM_UNI_MODULE */
351