]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i4b/driver/i4b_ctl.c
This commit was generated by cvs2svn to compensate for changes in r53574,
[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  * $FreeBSD$
31  *
32  *      last edit-date: [Tue Jun  8 09:27:15 1999]
33  *
34  *---------------------------------------------------------------------------*/
35
36 #include "i4bctl.h"
37
38 #if NI4BCTL > 1
39 #error "only 1 (one) i4bctl device allowed!"
40 #endif
41
42 #if NI4BCTL > 0
43
44 #include <sys/param.h>
45
46 #if defined(__FreeBSD__) && __FreeBSD__ >= 3
47 #include <sys/ioccom.h>
48 #include <i386/isa/isa_device.h>
49 #else
50 #include <sys/ioctl.h>
51 #endif
52
53 #include <sys/kernel.h>
54 #include <sys/systm.h>
55 #include <sys/conf.h>
56 #include <sys/mbuf.h>
57 #include <sys/proc.h>
58 #include <sys/fcntl.h>
59 #include <sys/socket.h>
60 #include <net/if.h>
61
62 #ifdef __FreeBSD__
63 #include <machine/i4b_debug.h>
64 #include <machine/i4b_ioctl.h>
65 #elif defined(__bsdi__)
66 #include <i4b/i4b_debug.h>
67 #include <i4b/i4b_ioctl.h>
68 #else
69 #include <machine/bus.h>
70 #include <sys/device.h>
71 #include <i4b/i4b_debug.h>
72 #include <i4b/i4b_ioctl.h>
73 #endif
74
75 #include <i4b/include/i4b_global.h>
76 #include <i4b/include/i4b_mbuf.h>
77 #include <i4b/layer1/i4b_l1.h>
78 #include <i4b/layer2/i4b_l2.h>
79
80 static int openflag = 0;
81
82 #if BSD > 199306 && defined(__FreeBSD__)
83 static  d_open_t        i4bctlopen;
84 static  d_close_t       i4bctlclose;
85 static  d_ioctl_t       i4bctlioctl;
86
87 #ifdef OS_USES_POLL
88 static d_poll_t         i4bctlpoll;
89 #define POLLFIELD       i4bctlpoll
90 #else
91 #define POLLFIELD       noselect
92 #endif
93
94 #define CDEV_MAJOR 55
95
96 #if defined (__FreeBSD_version) && __FreeBSD_version >= 400006
97 static struct cdevsw i4bctl_cdevsw = {
98         /* open */      i4bctlopen,
99         /* close */     i4bctlclose,
100         /* read */      noread,
101         /* write */     nowrite,
102         /* ioctl */     i4bctlioctl,
103         /* poll */      POLLFIELD,
104         /* mmap */      nommap,
105         /* strategy */  nostrategy,
106         /* name */      "i4bctl",
107         /* maj */       CDEV_MAJOR,
108         /* dump */      nodump,
109         /* psize */     nopsize,
110         /* flags */     0,
111         /* bmaj */      -1
112 };
113 #else
114 static struct cdevsw i4bctl_cdevsw = 
115         { i4bctlopen,   i4bctlclose,    noread,         nowrite,
116           i4bctlioctl,  nostop,         nullreset,      nodevtotty,
117           POLLFIELD,    nommap,         NULL,   "i4bctl", NULL, -1 };
118 #endif
119
120 static void i4bctlattach(void *);
121 PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
122
123 #define PDEVSTATIC      static
124 #endif /* __FreeBSD__ */
125
126 #ifndef __FreeBSD__
127 #define PDEVSTATIC      /* */
128 void i4bctlattach __P((void));
129 int i4bctlopen __P((dev_t dev, int flag, int fmt, struct proc *p));
130 int i4bctlclose __P((dev_t dev, int flag, int fmt, struct proc *p));
131 #ifdef __bsdi__
132 int i4bctlioctl __P((dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p));
133 #else
134 int i4bctlioctl __P((dev_t dev, int cmd, caddr_t data, int flag, struct proc *p));
135 #endif
136 #endif  /* !FreeBSD */
137
138 #if BSD > 199306 && defined(__FreeBSD__)
139 /*---------------------------------------------------------------------------*
140  *      initialization at kernel load time
141  *---------------------------------------------------------------------------*/
142 static void
143 i4bctlinit(void *unused)
144 {
145 #if defined (__FreeBSD_version) && __FreeBSD_version >= 400006
146         cdevsw_add(&i4bctl_cdevsw);
147 #else
148         dev_t dev = makedev(CDEV_MAJOR, 0);
149         cdevsw_add(&dev, &i4bctl_cdevsw, NULL);
150 #endif
151 }
152
153 SYSINIT(i4bctldev, SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, &i4bctlinit, NULL);
154
155 #endif /* BSD > 199306 && defined(__FreeBSD__) */
156
157 #ifdef __bsdi__
158 int i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux);
159 void dummy_i4bctlattach(struct device*, struct device *, void *);
160
161 #define CDEV_MAJOR 64
162
163 static struct cfdriver i4bctlcd =
164         { NULL, "i4bctl", i4bctlmatch, dummy_i4bctlattach, DV_DULL,
165           sizeof(struct cfdriver) };
166 struct devsw i4bctlsw = 
167         { &i4bctlcd,
168           i4bctlopen,   i4bctlclose,    noread,         nowrite,
169           i4bctlioctl,  seltrue,        nommap,         nostrat,
170           nodump,       nopsize,        0,              nostop
171 };
172
173 int
174 i4bctlmatch(struct device *parent, struct cfdata *cf, void *aux)
175 {
176         printf("i4bctlmatch: aux=0x%x\n", aux);
177         return 1;
178 }
179 void
180 dummy_i4bctlattach(struct device *parent, struct device *self, void *aux)
181 {
182         printf("dummy_i4bctlattach: aux=0x%x\n", aux);
183 }
184 #endif /* __bsdi__ */
185 /*---------------------------------------------------------------------------*
186  *      interface attach routine
187  *---------------------------------------------------------------------------*/
188 PDEVSTATIC void
189 #ifdef __FreeBSD__
190 i4bctlattach(void *dummy)
191 #else
192 i4bctlattach()
193 #endif
194 {
195 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
196         printf("i4bctl: ISDN system control port attached\n");
197 #endif
198         make_dev(&i4bctl_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "i4bctl");
199 }
200
201 /*---------------------------------------------------------------------------*
202  *      i4bctlopen - device driver open routine
203  *---------------------------------------------------------------------------*/
204 PDEVSTATIC int
205 i4bctlopen(dev_t dev, int flag, int fmt, struct proc *p)
206 {
207         if(minor(dev))
208                 return (ENXIO);
209
210         if(openflag)
211                 return (EBUSY);
212         
213         openflag = 1;
214         
215         return (0);
216 }
217
218 /*---------------------------------------------------------------------------*
219  *      i4bctlclose - device driver close routine
220  *---------------------------------------------------------------------------*/
221 PDEVSTATIC int
222 i4bctlclose(dev_t dev, int flag, int fmt, struct proc *p)
223 {
224         openflag = 0;
225         return (0);
226 }
227
228 /*---------------------------------------------------------------------------*
229  *      i4bctlioctl - device driver ioctl routine
230  *---------------------------------------------------------------------------*/
231 PDEVSTATIC int
232 #if defined (__FreeBSD_version) && __FreeBSD_version >= 300003
233 i4bctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
234 #elif defined(__bsdi__)
235 i4bctlioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct proc *p)
236 #else
237 i4bctlioctl(dev_t dev, int cmd, caddr_t data, int flag, struct proc *p)
238 #endif
239 {
240         ctl_debug_t *cdbg;      
241         int error = 0;
242         
243 #ifndef DO_I4B_DEBUG
244        return(ENODEV);
245 #else
246         if(minor(dev))
247                 return(ENODEV);
248
249         switch(cmd)
250         {
251                 case I4B_CTL_GET_DEBUG:
252                         cdbg = (ctl_debug_t *)data;
253                         cdbg->l1 = i4b_l1_debug;
254                         cdbg->l2 = i4b_l2_debug;
255                         cdbg->l3 = i4b_l3_debug;
256                         cdbg->l4 = i4b_l4_debug;
257                         break;
258                 
259                 case I4B_CTL_SET_DEBUG:
260                         cdbg = (ctl_debug_t *)data;
261                         i4b_l1_debug = cdbg->l1;
262                         i4b_l2_debug = cdbg->l2;
263                         i4b_l3_debug = cdbg->l3;
264                         i4b_l4_debug = cdbg->l4;
265                         break;
266
267                 case I4B_CTL_GET_HSCXSTAT:
268                 {
269                         hscxstat_t *hst;
270                         struct isic_softc *sc;
271                         hst = (hscxstat_t *)data;
272
273                         if( hst->unit < 0               ||
274                             hst->unit > ISIC_MAXUNIT    ||
275                             hst->chan < 0               ||
276                             hst->chan > 1 )
277                         {
278                                 error = EINVAL;
279                                 break;
280                         }
281                           
282 #ifndef __FreeBSD__
283                         sc = isic_find_sc(hst->unit);
284 #else
285                         sc = &isic_sc[hst->unit];
286 #endif
287                         hst->vfr = sc->sc_chan[hst->chan].stat_VFR;
288                         hst->rdo = sc->sc_chan[hst->chan].stat_RDO;
289                         hst->crc = sc->sc_chan[hst->chan].stat_CRC;
290                         hst->rab = sc->sc_chan[hst->chan].stat_RAB;
291                         hst->xdu = sc->sc_chan[hst->chan].stat_XDU;
292                         hst->rfo = sc->sc_chan[hst->chan].stat_RFO;
293                         break;
294                 }
295
296                 case I4B_CTL_CLR_HSCXSTAT:
297                 {
298                         hscxstat_t *hst;
299                         struct isic_softc *sc;
300                         hst = (hscxstat_t *)data;
301
302                         if( hst->unit < 0               ||
303                             hst->unit > ISIC_MAXUNIT    ||
304                             hst->chan < 0               ||
305                             hst->chan > 1 )
306                         {
307                                 error = EINVAL;
308                                 break;
309                         }
310                           
311 #ifndef __FreeBSD__
312                         sc = isic_find_sc(hst->unit);
313 #else
314                         sc = &isic_sc[hst->unit];
315 #endif
316
317                         sc->sc_chan[hst->chan].stat_VFR = 0;
318                         sc->sc_chan[hst->chan].stat_RDO = 0;
319                         sc->sc_chan[hst->chan].stat_CRC = 0;
320                         sc->sc_chan[hst->chan].stat_RAB = 0;
321                         sc->sc_chan[hst->chan].stat_XDU = 0;
322                         sc->sc_chan[hst->chan].stat_RFO = 0;
323                         
324                         break;
325                 }
326
327                 case I4B_CTL_GET_LAPDSTAT:
328                 {
329                         l2stat_t *l2s;
330                         l2_softc_t *sc;
331                         l2s = (l2stat_t *)data;
332
333                         if( l2s->unit < 0 || l2s->unit > ISIC_MAXUNIT)
334                         {
335                                 error = EINVAL;
336                                 break;
337                         }
338                           
339                         sc = &l2_softc[l2s->unit];
340
341                         bcopy(&sc->stat, &l2s->lapdstat, sizeof(lapdstat_t));
342                         break;
343                 }
344
345                 case I4B_CTL_CLR_LAPDSTAT:
346                 {
347                         int *up;
348                         l2_softc_t *sc;
349                         up = (int *)data;
350
351                         if( *up < 0 || *up > ISIC_MAXUNIT)
352                         {
353                                 error = EINVAL;
354                                 break;
355                         }
356                           
357                         sc = &l2_softc[*up];
358
359                         bzero(&sc->stat, sizeof(lapdstat_t));
360                         break;
361                 }
362
363                 default:
364                         error = ENOTTY;
365                         break;
366         }
367         return(error);
368 #endif DO_I4B_DEBUG
369 }
370
371 #if defined(__FreeBSD__) && defined(OS_USES_POLL)
372
373 /*---------------------------------------------------------------------------*
374  *      i4bctlpoll - device driver poll routine
375  *---------------------------------------------------------------------------*/
376 static int
377 i4bctlpoll (dev_t dev, int events, struct proc *p)
378 {
379         return (ENODEV);
380 }
381
382 #endif
383
384 #endif /* NI4BCTL > 0 */