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