Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[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.2 2003/06/17 04:28:49 dillon 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 <netatm/kern_include.h>
43
44 /*
45  * External functions
46  */
47 int             sscop_start __P((void));
48 int             sscop_stop __P((void));
49 int             sscf_uni_start __P((void));
50 int             sscf_uni_stop __P((void));
51 int             uniip_start __P((void));
52 int             uniip_stop __P((void));
53 int             unisig_start __P((void));
54 int             unisig_stop __P((void));
55
56 /*
57  * Local functions
58  */
59 static int      uni_start __P((void));
60 static int      uni_stop __P((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()
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()
132 {
133         int     err, s = splnet();
134
135         /*
136          * Terminate uni sub-services
137          */
138         err = uniip_stop();
139         if (err)
140                 goto done;
141
142         err = unisig_stop();
143         if (err)
144                 goto done;
145
146         err = sscf_uni_stop();
147         if (err)
148                 goto done;
149
150         err = sscop_stop();
151         if (err)
152                 goto done;
153
154 done:
155         (void) splx(s);
156         return (err);
157 }
158
159
160 #ifdef ATM_UNI_MODULE
161 /*
162  *******************************************************************
163  *
164  * Loadable Module Support
165  *
166  *******************************************************************
167  */
168 static int      uni_doload __P((void));
169 static int      uni_dounload __P((void));
170
171 /*
172  * Generic module load processing
173  * 
174  * This function is called by an OS-specific function when this
175  * module is being loaded.
176  *
177  * Arguments:
178  *      none
179  *
180  * Returns:
181  *      0       load was successful 
182  *      errno   load failed - reason indicated
183  *
184  */
185 static int
186 uni_doload()
187 {
188         int     err = 0;
189
190         /*
191          * Start us up
192          */
193         err = uni_start();
194         if (err)
195                 /* Problems, clean up */
196                 (void)uni_stop();
197
198         return (err);
199 }
200
201
202 /*
203  * Generic module unload processing
204  * 
205  * This function is called by an OS-specific function when this
206  * module is being unloaded.
207  *
208  * Arguments:
209  *      none
210  *
211  * Returns:
212  *      0       unload was successful 
213  *      errno   unload failed - reason indicated
214  *
215  */
216 static int
217 uni_dounload()
218 {
219         int     err = 0;
220
221         /*
222          * OK, try to clean up our mess
223          */
224         err = uni_stop();
225
226         return (err);
227 }
228
229
230 #ifdef sun
231 /*
232  * Loadable driver description
233  */
234 struct vdldrv uni_drv = {
235         VDMAGIC_PSEUDO, /* Pseudo Driver */
236         "uni_mod",      /* name */
237         NULL,           /* dev_ops */
238         NULL,           /* bdevsw */
239         NULL,           /* cdevsw */
240         0,              /* blockmajor */
241         0               /* charmajor */
242 };
243
244
245 /*
246  * Loadable module support entry point
247  * 
248  * This is the routine called by the vd driver for all loadable module
249  * functions for this pseudo driver.  This routine name must be specified
250  * on the modload(1) command.  This routine will be called whenever the
251  * modload(1), modunload(1) or modstat(1) commands are issued for this
252  * module.
253  *
254  * Arguments:
255  *      cmd     vd command code
256  *      vdp     pointer to vd driver's structure
257  *      vdi     pointer to command-specific vdioctl_* structure
258  *      vds     pointer to status structure (VDSTAT only)
259  *
260  * Returns:
261  *      0       command was successful 
262  *      errno   command failed - reason indicated
263  *
264  */
265 int
266 uni_mod(cmd, vdp, vdi, vds)
267         int             cmd;
268         struct vddrv    *vdp;
269         caddr_t         vdi;
270         struct vdstat   *vds;
271 {
272         int     err = 0;
273
274         switch (cmd) {
275
276         case VDLOAD:
277                 /*
278                  * Module Load
279                  *
280                  * We dont support any user configuration
281                  */
282                 err = uni_doload();
283                 if (err == 0)
284                         /* Let vd driver know about us */
285                         vdp->vdd_vdtab = (struct vdlinkage *)&uni_drv;
286                 break;
287
288         case VDUNLOAD:
289                 /*
290                  * Module Unload
291                  */
292                 err = uni_dounload();
293                 break;
294
295         case VDSTAT:
296                 /*
297                  * Module Status
298                  */
299
300                 /* Not much to say at the moment */
301
302                 break;
303
304         default:
305                 log(LOG_ERR, "uni_mod: Unknown vd command 0x%x\n", cmd);
306                 err = EINVAL;
307         }
308
309         return (err);
310 }
311 #endif  /* sun */
312
313 #ifdef __FreeBSD__
314
315 #include <sys/exec.h>
316 #include <sys/sysent.h>
317 #include <sys/lkm.h>
318
319 /*
320  * Loadable miscellaneous module description
321  */
322 MOD_MISC(uni);
323
324
325 /*
326  * Loadable module support "load" entry point
327  * 
328  * This is the routine called by the lkm driver whenever the
329  * modload(1) command is issued for this module.
330  *
331  * Arguments:
332  *      lkmtp   pointer to lkm drivers's structure
333  *      cmd     lkm command code
334  *
335  * Returns:
336  *      0       command was successful 
337  *      errno   command failed - reason indicated
338  *
339  */
340 static int
341 uni_load(lkmtp, cmd)
342         struct lkm_table        *lkmtp;
343         int             cmd;
344 {
345         return(uni_doload());
346 }
347
348
349 /*
350  * Loadable module support "unload" entry point
351  * 
352  * This is the routine called by the lkm driver whenever the
353  * modunload(1) command is issued for this module.
354  *
355  * Arguments:
356  *      lkmtp   pointer to lkm drivers's structure
357  *      cmd     lkm command code
358  *
359  * Returns:
360  *      0       command was successful 
361  *      errno   command failed - reason indicated
362  *
363  */
364 static int
365 uni_unload(lkmtp, cmd)
366         struct lkm_table        *lkmtp;
367         int             cmd;
368 {
369         return(uni_dounload());
370 }
371
372
373 /*
374  * Loadable module support entry point
375  * 
376  * This is the routine called by the lkm driver for all loadable module
377  * functions for this driver.  This routine name must be specified
378  * on the modload(1) command.  This routine will be called whenever the
379  * modload(1), modunload(1) or modstat(1) commands are issued for this
380  * module.
381  *
382  * Arguments:
383  *      lkmtp   pointer to lkm drivers's structure
384  *      cmd     lkm command code
385  *      ver     lkm version
386  *
387  * Returns:
388  *      0       command was successful 
389  *      errno   command failed - reason indicated
390  *
391  */
392 int
393 uni_mod(lkmtp, cmd, ver)
394         struct lkm_table        *lkmtp;
395         int             cmd;
396         int             ver;
397 {
398         MOD_DISPATCH(uni, lkmtp, cmd, ver,
399                 uni_load, uni_unload, lkm_nullcmd);
400 }
401 #endif  /* __FreeBSD__ */
402
403 #else   /* !ATM_UNI_MODULE */
404
405 /*
406  *******************************************************************
407  *
408  * Kernel Compiled Module Support
409  *
410  *******************************************************************
411  */
412 static void     uni_doload __P((void *));
413
414 SYSINIT(atmuni, SI_SUB_PROTO_END, SI_ORDER_ANY, uni_doload, NULL)
415
416 /*
417  * Kernel initialization
418  * 
419  * Arguments:
420  *      arg     Not used
421  *
422  * Returns:
423  *      none
424  *
425  */
426 static void
427 uni_doload(void *arg)
428 {
429         int     err = 0;
430
431         /*
432          * Start us up
433          */
434         err = uni_start();
435         if (err) {
436                 /* Problems, clean up */
437                 (void)uni_stop();
438
439                 log(LOG_ERR, "ATM UNI unable to initialize (%d)!!\n", err);
440         }
441         return;
442 }
443 #endif  /* ATM_UNI_MODULE */
444