kernel: Remove most definitions of CDEV_MAJOR.
[dragonfly.git] / sys / net / i4b / driver / i4b_ctl.c
1 /*
2  * Copyright (c) 1997, 2000 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.37 2000/05/31 08:04:43 hm Exp $
31  *
32  * $FreeBSD: src/sys/i4b/driver/i4b_ctl.c,v 1.10.2.3 2001/08/12 16:22:48 hm Exp $
33  *
34  *      last edit-date: [Sat Aug 11 18:06:38 2001]
35  *
36  *---------------------------------------------------------------------------*/
37
38 #include "use_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 #include <sys/kernel.h>
49 #include <sys/systm.h>
50 #include <sys/conf.h>
51 #include <sys/device.h>
52 #include <sys/socket.h>
53 #include <net/if.h>
54
55 #include <net/i4b/include/machine/i4b_debug.h>
56 #include <net/i4b/include/machine/i4b_ioctl.h>
57
58 #include "../include/i4b_global.h"
59 #include "../include/i4b_l3l4.h"
60 #include "../layer2/i4b_l2.h"
61
62 static int openflag = 0;
63
64 static  d_open_t        i4bctlopen;
65 static  d_close_t       i4bctlclose;
66 static  d_ioctl_t       i4bctlioctl;
67
68 static struct dev_ops i4bctl_ops = {
69         { "i4bctl", 0, 0 },
70         .d_open =      i4bctlopen,
71         .d_close =     i4bctlclose,
72         .d_ioctl =     i4bctlioctl,
73 };
74
75 static void i4bctlattach(void *);
76 PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
77
78 #define PDEVSTATIC      static
79
80 /*---------------------------------------------------------------------------*
81  *      interface attach routine
82  *---------------------------------------------------------------------------*/
83 PDEVSTATIC void
84 i4bctlattach(void *dummy)
85 {
86 #ifndef HACK_NO_PSEUDO_ATTACH_MSG
87         kprintf("i4bctl: ISDN system control port attached\n");
88 #endif
89 }
90
91 /*---------------------------------------------------------------------------*
92  *      i4bctlopen - device driver open routine
93  *---------------------------------------------------------------------------*/
94 PDEVSTATIC int
95 i4bctlopen(struct dev_open_args *ap)
96 {
97         cdev_t dev = ap->a_head.a_dev;
98         if(minor(dev))
99                 return (ENXIO);
100         if(openflag)
101                 return (EBUSY);
102         openflag = 1;
103         return (0);
104 }
105
106 /*---------------------------------------------------------------------------*
107  *      i4bctlclose - device driver close routine
108  *---------------------------------------------------------------------------*/
109 PDEVSTATIC int
110 i4bctlclose(struct dev_close_args *ap)
111 {
112         openflag = 0;
113         return (0);
114 }
115
116 /*---------------------------------------------------------------------------*
117  *      i4bctlioctl - device driver ioctl routine
118  *---------------------------------------------------------------------------*/
119 PDEVSTATIC int
120 i4bctlioctl(struct dev_ioctl_args *ap)
121 {
122         cdev_t dev = ap->a_head.a_dev;
123 #if DO_I4B_DEBUG
124         ctl_debug_t *cdbg;      
125         int error = 0;
126 #endif
127         
128 #if !DO_I4B_DEBUG
129        return(ENODEV);
130 #else
131         if(minor(dev))
132                 return(ENODEV);
133
134         switch(ap->a_cmd)
135         {
136                 case I4B_CTL_GET_DEBUG:
137                         cdbg = (ctl_debug_t *)ap->a_data;
138                         cdbg->l1 = i4b_l1_debug;
139                         cdbg->l2 = i4b_l2_debug;
140                         cdbg->l3 = i4b_l3_debug;
141                         cdbg->l4 = i4b_l4_debug;
142                         break;
143                 
144                 case I4B_CTL_SET_DEBUG:
145                         cdbg = (ctl_debug_t *)ap->a_data;
146                         i4b_l1_debug = cdbg->l1;
147                         i4b_l2_debug = cdbg->l2;
148                         i4b_l3_debug = cdbg->l3;
149                         i4b_l4_debug = cdbg->l4;
150                         break;
151
152                 case I4B_CTL_GET_CHIPSTAT:
153                 {
154                         struct chipstat *cst;
155                         cst = (struct chipstat *)ap->a_data;
156                         (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_GCST, cst);
157                         break;
158                 }
159
160                 case I4B_CTL_CLR_CHIPSTAT:
161                 {
162                         struct chipstat *cst;
163                         cst = (struct chipstat *)ap->a_data;
164                         (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_CCST, cst);
165                         break;
166                 }
167
168                 case I4B_CTL_GET_LAPDSTAT:
169                 {
170                         l2stat_t *l2s;
171                         l2_softc_t *sc;
172                         l2s = (l2stat_t *)ap->a_data;
173
174                         if( l2s->unit < 0 || l2s->unit > MAXL1UNITS)
175                         {
176                                 error = EINVAL;
177                                 break;
178                         }
179                           
180                         sc = &l2_softc[l2s->unit];
181
182                         bcopy(&sc->stat, &l2s->lapdstat, sizeof(lapdstat_t));
183                         break;
184                 }
185
186                 case I4B_CTL_CLR_LAPDSTAT:
187                 {
188                         int *up;
189                         l2_softc_t *sc;
190                         up = (int *)ap->a_data;
191
192                         if( *up < 0 || *up > MAXL1UNITS)
193                         {
194                                 error = EINVAL;
195                                 break;
196                         }
197                           
198                         sc = &l2_softc[*up];
199
200                         bzero(&sc->stat, sizeof(lapdstat_t));
201                         break;
202                 }
203
204                 default:
205                         error = ENOTTY;
206                         break;
207         }
208         return(error);
209 #endif /* DO_I4B_DEBUG */
210 }
211
212 #endif /* NI4BCTL > 0 */