]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i4b/driver/i4b_ctl.c
This commit was generated by cvs2svn to compensate for changes in r58653,
[FreeBSD/FreeBSD.git] / sys / i4b / driver / i4b_ctl.c
1 /*
2  * Copyright (c) 1997, 1999 Hellmuth Michaelis. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  *
25  *---------------------------------------------------------------------------
26  *
27  *      i4b_ctl.c - i4b system control port driver
28  *      ------------------------------------------
29  *
30  *      $Id: i4b_ctl.c,v 1.30 1999/12/13 21:25:23 hm Exp $
31  *
32  * $FreeBSD$
33  *
34  *      last edit-date: [Mon Dec 13 21:38:15 1999]
35  *
36  *---------------------------------------------------------------------------*/
37
38 #include "i4bctl.h"
39
40 #if NI4BCTL > 1
41 #error "only 1 (one) i4bctl device allowed!"
42 #endif
43
44 #if NI4BCTL > 0
45
46 #include <sys/param.h>
47
48 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
49 #include <sys/ioccom.h>
50 #include <i386/isa/isa_device.h>
51 #else
52 #include <sys/ioctl.h>
53 #endif
54
55 #include <sys/kernel.h>
56 #include <sys/systm.h>
57 #include <sys/conf.h>
58 #include <sys/mbuf.h>
59 #include <sys/proc.h>
60 #include <sys/fcntl.h>
61 #include <sys/socket.h>
62 #include <net/if.h>
63
64 #ifdef __FreeBSD__
65
66 #if defined(__FreeBSD__) && __FreeBSD__ == 3
67 #include "opt_devfs.h"
68 #endif
69
70 #ifdef DEVFS
71 #include <sys/devfsext.h>
72 #endif
73
74 #endif /* __FreeBSD__ */
75
76 #ifdef __FreeBSD__
77 #include <machine/i4b_debug.h>
78 #include <machine/i4b_ioctl.h>
79 #elif defined(__bsdi__)
80 #include <i4b/i4b_debug.h>
81 #include <i4b/i4b_ioctl.h>
82 #else
83 #include <machine/bus.h>
84 #include <sys/device.h>
85 #include <i4b/i4b_debug.h>
86 #include <i4b/i4b_ioctl.h>
87 #endif
88
89 #include <i4b/include/i4b_global.h>
90 #include <i4b/include/i4b_mbuf.h>
91 #include <i4b/layer1/i4b_l1.h>
92 #include <i4b/layer2/i4b_l2.h>
93
94 static int openflag = 0;
95
96 #if BSD > 199306 && defined(__FreeBSD__)
97 static  d_open_t        i4bctlopen;
98 static  d_close_t       i4bctlclose;
99 static  d_ioctl_t       i4bctlioctl;
100
101 #ifdef OS_USES_POLL
102 static d_poll_t         i4bctlpoll;
103 #define POLLFIELD       i4bctlpoll
104 #else
105 #define POLLFIELD       noselect
106 #endif
107
108 #define CDEV_MAJOR 55
109
110 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
111 static struct cdevsw i4bctl_cdevsw = {
112         /* open */      i4bctlopen,
113         /* close */     i4bctlclose,
114         /* read */      noread,
115         /* write */     nowrite,
116         /* ioctl */     i4bctlioctl,
117         /* poll */      POLLFIELD,
118         /* mmap */      nommap,
119         /* strategy */  nostrategy,
120         /* name */      "i4bctl",
121         /* maj */       CDEV_MAJOR,
122         /* dump */      nodump,
123         /* psize */     nopsize,
124         /* flags */     0,
125         /* bmaj */      -1
126 };
127 #else
128 static struct cdevsw i4bctl_cdevsw = 
129         { i4bctlopen,   i4bctlclose,    noread,         nowrite,
130           i4bctlioctl,  nostop,         nullreset,      nodevtotty,
131           POLLFIELD,    nommap,         NULL,   "i4bctl", NULL, -1 };
132 #endif
133
134 static void i4bctlattach(void *);
135 PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
136
137 #define PDEVSTATIC      static
138 #endif /* __FreeBSD__ */
139
140 #if defined(__FreeBSD__) && __FreeBSD__ == 3
141 #ifdef DEVFS
142 static void *devfs_token;
143 #endif
144 #endif
145
146 #ifndef __FreeBSD__
147 #define PDEVSTATIC      /* */
148 void i4bctlattach __P((void));
149 int i4bctlopen __P((dev_t dev, int flag, int fmt, struct proc *p));
150 int i4bctlclose __P((dev_t dev, int flag, int fmt, struct proc *p));
151 #ifdef __bsdi__
152 int i4bctlioctl __P((dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p));
153 #else
154 int i4bctlioctl __P((dev_t dev, int cmd, caddr_t data, int flag, struct proc *p));
155 #endif
156 #endif  /* !FreeBSD */
157
158 #if BSD > 199306 && defined(__FreeBSD__)
159 /*---------------------------------------------------------------------------*
160  *      initialization at kernel load time
161  *---------------------------------------------------------------------------*/
162 static void
163 i4bctlinit(void *unused)
164 {
165 #if defined(__FreeBSD__) && __FreeBSD__ >= 4
166         cdevsw_add(&i4bctl_cdevsw);
167 #else
168         dev_t dev = makedev(CDEV_MAJOR, 0);
169         cdevsw_add(&dev, &i4bctl_cdevsw, NULL);
170 #endif
171 }
172
173 SYSINIT(i4bctldev, SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, &i4bctlinit, NULL);
174
175 #endif /* BSD > 199306 && defined(__FreeBSD__) */
176
177 #ifdef __bsdi__
178 int i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux);
179 void dummy_i4bctlattach(struct device*, struct device *, void *);
180
181 #define CDEV_MAJOR 64
182
183 static struct cfdriver i4bctlcd =
184         { NULL, "i4bctl", i4bctlmatch, dummy_i4bctlattach, DV_DULL,
185           sizeof(struct cfdriver) };
186 struct devsw i4bctlsw = 
187         { &i4bctlcd,
188           i4bctlopen,   i4bctlclose,    noread,         nowrite,
189           i4bctlioctl,  seltrue,        nommap,         nostrat,
190           nodump,       nopsize,        0,              nostop
191 };
192
193 int
194 i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux)
195 {
196         printf("i4bctlmatch: aux=0x%x\n", aux);
197         return 1;
198 }
199 void
200 dummy_i4bctlattach(struct device *parent, struct device *self, void *aux)
201 {
202         printf("dummy_i4bctlattach: aux=0x%x\n", aux);
203 }
204 #endif /* __bsdi__ */
205 /*---------------------------------------------------------------------------*
206  *      interface attach routine
207  *---------------------------------------------------------------------------*/
208 PDEVSTATIC void
209 #ifdef __FreeBSD__
210 i4bctlattach(void *dummy)
211 #else
212 i4bctlattach()
213 #endif
214 {
215 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
216         printf("i4bctl: ISDN system control port attached\n");
217 #endif
218
219 #if defined(__FreeBSD__)
220 #if __FreeBSD__ == 3
221
222 #ifdef DEVFS
223         devfs_token = devfs_add_devswf(&i4bctl_cdevsw, 0, DV_CHR,
224                                        UID_ROOT, GID_WHEEL, 0600,
225                                        "i4bctl");
226 #endif
227
228 #else
229         make_dev(&i4bctl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "i4bctl");
230 #endif
231 #endif
232 }
233
234 /*---------------------------------------------------------------------------*
235  *      i4bctlopen - device driver open routine
236  *---------------------------------------------------------------------------*/
237 PDEVSTATIC int
238 i4bctlopen(dev_t dev, int flag, int fmt, struct proc *p)
239 {
240         if(minor(dev))
241                 return (ENXIO);
242
243         if(openflag)
244                 return (EBUSY);
245         
246         openflag = 1;
247         
248         return (0);
249 }
250
251 /*---------------------------------------------------------------------------*
252  *      i4bctlclose - device driver close routine
253  *---------------------------------------------------------------------------*/
254 PDEVSTATIC int
255 i4bctlclose(dev_t dev, int flag, int fmt, struct proc *p)
256 {
257         openflag = 0;
258         return (0);
259 }
260
261 /*---------------------------------------------------------------------------*
262  *      i4bctlioctl - device driver ioctl routine
263  *---------------------------------------------------------------------------*/
264 PDEVSTATIC int
265 #if defined (__FreeBSD_version) && __FreeBSD_version >= 300003
266 i4bctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
267 #elif defined(__bsdi__)
268 i4bctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
269 #else
270 i4bctlioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
271 #endif
272 {
273         ctl_debug_t *cdbg;      
274         int error = 0;
275         
276 #ifndef DO_I4B_DEBUG
277        return(ENODEV);
278 #else
279         if(minor(dev))
280                 return(ENODEV);
281
282         switch(cmd)
283         {
284                 case I4B_CTL_GET_DEBUG:
285                         cdbg = (ctl_debug_t *)data;
286                         cdbg->l1 = i4b_l1_debug;
287                         cdbg->l2 = i4b_l2_debug;
288                         cdbg->l3 = i4b_l3_debug;
289                         cdbg->l4 = i4b_l4_debug;
290                         break;
291                 
292                 case I4B_CTL_SET_DEBUG:
293                         cdbg = (ctl_debug_t *)data;
294                         i4b_l1_debug = cdbg->l1;
295                         i4b_l2_debug = cdbg->l2;
296                         i4b_l3_debug = cdbg->l3;
297                         i4b_l4_debug = cdbg->l4;
298                         break;
299
300                 case I4B_CTL_GET_HSCXSTAT:
301                 {
302                         hscxstat_t *hst;
303                         struct l1_softc *sc;
304                         hst = (hscxstat_t *)data;
305
306                         if( hst->unit < 0               ||
307                             hst->unit > ISIC_MAXUNIT    ||
308                             hst->chan < 0               ||
309                             hst->chan > 1 )
310                         {
311                                 error = EINVAL;
312                                 break;
313                         }
314                           
315 #ifndef __FreeBSD__
316                         sc = isic_find_sc(hst->unit);
317 #else
318                         sc = &l1_sc[hst->unit];
319 #endif
320                         hst->vfr = sc->sc_chan[hst->chan].stat_VFR;
321                         hst->rdo = sc->sc_chan[hst->chan].stat_RDO;
322                         hst->crc = sc->sc_chan[hst->chan].stat_CRC;
323                         hst->rab = sc->sc_chan[hst->chan].stat_RAB;
324                         hst->xdu = sc->sc_chan[hst->chan].stat_XDU;
325                         hst->rfo = sc->sc_chan[hst->chan].stat_RFO;
326                         break;
327                 }
328
329                 case I4B_CTL_CLR_HSCXSTAT:
330                 {
331                         hscxstat_t *hst;
332                         struct l1_softc *sc;
333                         hst = (hscxstat_t *)data;
334
335                         if( hst->unit < 0               ||
336                             hst->unit > ISIC_MAXUNIT    ||
337                             hst->chan < 0               ||
338                             hst->chan > 1 )
339                         {
340                                 error = EINVAL;
341                                 break;
342                         }
343                           
344 #ifndef __FreeBSD__
345                         sc = isic_find_sc(hst->unit);
346 #else
347                         sc = &l1_sc[hst->unit];
348 #endif
349
350                         sc->sc_chan[hst->chan].stat_VFR = 0;
351                         sc->sc_chan[hst->chan].stat_RDO = 0;
352                         sc->sc_chan[hst->chan].stat_CRC = 0;
353                         sc->sc_chan[hst->chan].stat_RAB = 0;
354                         sc->sc_chan[hst->chan].stat_XDU = 0;
355                         sc->sc_chan[hst->chan].stat_RFO = 0;
356                         
357                         break;
358                 }
359
360                 case I4B_CTL_GET_LAPDSTAT:
361                 {
362                         l2stat_t *l2s;
363                         l2_softc_t *sc;
364                         l2s = (l2stat_t *)data;
365
366                         if( l2s->unit < 0 || l2s->unit > ISIC_MAXUNIT)
367                         {
368                                 error = EINVAL;
369                                 break;
370                         }
371                           
372                         sc = &l2_softc[l2s->unit];
373
374                         bcopy(&sc->stat, &l2s->lapdstat, sizeof(lapdstat_t));
375                         break;
376                 }
377
378                 case I4B_CTL_CLR_LAPDSTAT:
379                 {
380                         int *up;
381                         l2_softc_t *sc;
382                         up = (int *)data;
383
384                         if( *up < 0 || *up > ISIC_MAXUNIT)
385                         {
386                                 error = EINVAL;
387                                 break;
388                         }
389                           
390                         sc = &l2_softc[*up];
391
392                         bzero(&sc->stat, sizeof(lapdstat_t));
393                         break;
394                 }
395
396                 default:
397                         error = ENOTTY;
398                         break;
399         }
400         return(error);
401 #endif DO_I4B_DEBUG
402 }
403
404 #if defined(__FreeBSD__) && defined(OS_USES_POLL)
405
406 /*---------------------------------------------------------------------------*
407  *      i4bctlpoll - device driver poll routine
408  *---------------------------------------------------------------------------*/
409 static int
410 i4bctlpoll (dev_t dev, int events, struct proc *p)
411 {
412         return (ENODEV);
413 }
414
415 #endif
416
417 #endif /* NI4BCTL > 0 */