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