Change the kernel dev_t, representing a pointer to a specinfo structure,
[dragonfly.git] / sys / net / i4b / driver / i4b_ctl.c
CommitLineData
984263bc
MD
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 $
b13267a5 33 * $DragonFly: src/sys/net/i4b/driver/i4b_ctl.c,v 1.13 2006/09/10 01:26:39 dillon Exp $
984263bc
MD
34 *
35 * last edit-date: [Sat Aug 11 18:06:38 2001]
36 *
37 *---------------------------------------------------------------------------*/
38
1f2de5d4 39#include "use_i4bctl.h"
984263bc
MD
40
41#if NI4BCTL > 1
42#error "only 1 (one) i4bctl device allowed!"
43#endif
44
45#if NI4BCTL > 0
46
47#include <sys/param.h>
48
984263bc
MD
49#include <sys/kernel.h>
50#include <sys/systm.h>
51#include <sys/conf.h>
fef8985e
MD
52#include <sys/device.h>
53#include <sys/ioccom.h>
984263bc
MD
54#include <sys/socket.h>
55#include <net/if.h>
56
1f2de5d4
MD
57#include <net/i4b/include/machine/i4b_debug.h>
58#include <net/i4b/include/machine/i4b_ioctl.h>
984263bc 59
1f2de5d4
MD
60#include "../include/i4b_global.h"
61#include "../include/i4b_l3l4.h"
62#include "../layer2/i4b_l2.h"
984263bc
MD
63
64static int openflag = 0;
65
984263bc
MD
66static d_open_t i4bctlopen;
67static d_close_t i4bctlclose;
68static d_ioctl_t i4bctlioctl;
69
984263bc
MD
70static d_poll_t i4bctlpoll;
71#define POLLFIELD i4bctlpoll
984263bc
MD
72
73#define CDEV_MAJOR 55
74
fef8985e
MD
75static struct dev_ops i4bctl_ops = {
76 { "i4bctl", CDEV_MAJOR, 0 },
77 .d_open = i4bctlopen,
78 .d_close = i4bctlclose,
79 .d_ioctl = i4bctlioctl,
80 .d_poll = POLLFIELD,
984263bc 81};
984263bc
MD
82
83static void i4bctlattach(void *);
84PSEUDO_SET(i4bctlattach, i4b_i4bctldrv);
85
86#define PDEVSTATIC static
984263bc 87
984263bc
MD
88/*---------------------------------------------------------------------------*
89 * initialization at kernel load time
90 *---------------------------------------------------------------------------*/
91static void
92i4bctlinit(void *unused)
93{
fef8985e 94 dev_ops_add(&i4bctl_ops, 0, 0);
984263bc
MD
95}
96
97SYSINIT(i4bctldev, SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR, &i4bctlinit, NULL);
98
984263bc
MD
99/*---------------------------------------------------------------------------*
100 * interface attach routine
101 *---------------------------------------------------------------------------*/
102PDEVSTATIC void
984263bc 103i4bctlattach(void *dummy)
984263bc
MD
104{
105#ifndef HACK_NO_PSEUDO_ATTACH_MSG
106 printf("i4bctl: ISDN system control port attached\n");
107#endif
984263bc
MD
108}
109
110/*---------------------------------------------------------------------------*
111 * i4bctlopen - device driver open routine
112 *---------------------------------------------------------------------------*/
113PDEVSTATIC int
fef8985e 114i4bctlopen(struct dev_open_args *ap)
984263bc 115{
b13267a5 116 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
117 if(minor(dev))
118 return (ENXIO);
984263bc
MD
119 if(openflag)
120 return (EBUSY);
984263bc 121 openflag = 1;
984263bc
MD
122 return (0);
123}
124
125/*---------------------------------------------------------------------------*
126 * i4bctlclose - device driver close routine
127 *---------------------------------------------------------------------------*/
128PDEVSTATIC int
fef8985e 129i4bctlclose(struct dev_close_args *ap)
984263bc
MD
130{
131 openflag = 0;
132 return (0);
133}
134
135/*---------------------------------------------------------------------------*
136 * i4bctlioctl - device driver ioctl routine
137 *---------------------------------------------------------------------------*/
138PDEVSTATIC int
fef8985e 139i4bctlioctl(struct dev_ioctl_args *ap)
984263bc 140{
b13267a5 141 cdev_t dev = ap->a_head.a_dev;
984263bc
MD
142#if DO_I4B_DEBUG
143 ctl_debug_t *cdbg;
144 int error = 0;
145#endif
146
147#if !DO_I4B_DEBUG
148 return(ENODEV);
149#else
150 if(minor(dev))
151 return(ENODEV);
152
fef8985e 153 switch(ap->a_cmd)
984263bc
MD
154 {
155 case I4B_CTL_GET_DEBUG:
fef8985e 156 cdbg = (ctl_debug_t *)ap->a_data;
984263bc
MD
157 cdbg->l1 = i4b_l1_debug;
158 cdbg->l2 = i4b_l2_debug;
159 cdbg->l3 = i4b_l3_debug;
160 cdbg->l4 = i4b_l4_debug;
161 break;
162
163 case I4B_CTL_SET_DEBUG:
fef8985e 164 cdbg = (ctl_debug_t *)ap->a_data;
984263bc
MD
165 i4b_l1_debug = cdbg->l1;
166 i4b_l2_debug = cdbg->l2;
167 i4b_l3_debug = cdbg->l3;
168 i4b_l4_debug = cdbg->l4;
169 break;
170
171 case I4B_CTL_GET_CHIPSTAT:
172 {
173 struct chipstat *cst;
fef8985e 174 cst = (struct chipstat *)ap->a_data;
984263bc
MD
175 (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_GCST, cst);
176 break;
177 }
178
179 case I4B_CTL_CLR_CHIPSTAT:
180 {
181 struct chipstat *cst;
fef8985e 182 cst = (struct chipstat *)ap->a_data;
984263bc
MD
183 (*ctrl_desc[cst->driver_unit].N_MGMT_COMMAND)(cst->driver_unit, CMR_CCST, cst);
184 break;
185 }
186
187 case I4B_CTL_GET_LAPDSTAT:
188 {
189 l2stat_t *l2s;
190 l2_softc_t *sc;
fef8985e 191 l2s = (l2stat_t *)ap->a_data;
984263bc
MD
192
193 if( l2s->unit < 0 || l2s->unit > MAXL1UNITS)
194 {
195 error = EINVAL;
196 break;
197 }
198
199 sc = &l2_softc[l2s->unit];
200
201 bcopy(&sc->stat, &l2s->lapdstat, sizeof(lapdstat_t));
202 break;
203 }
204
205 case I4B_CTL_CLR_LAPDSTAT:
206 {
207 int *up;
208 l2_softc_t *sc;
fef8985e 209 up = (int *)ap->a_data;
984263bc
MD
210
211 if( *up < 0 || *up > MAXL1UNITS)
212 {
213 error = EINVAL;
214 break;
215 }
216
217 sc = &l2_softc[*up];
218
219 bzero(&sc->stat, sizeof(lapdstat_t));
220 break;
221 }
222
223 default:
224 error = ENOTTY;
225 break;
226 }
227 return(error);
1d94a9ab 228#endif /* DO_I4B_DEBUG */
984263bc
MD
229}
230
984263bc
MD
231/*---------------------------------------------------------------------------*
232 * i4bctlpoll - device driver poll routine
233 *---------------------------------------------------------------------------*/
234static int
fef8985e 235i4bctlpoll (struct dev_poll_args *ap)
984263bc
MD
236{
237 return (ENODEV);
238}
239
984263bc 240#endif /* NI4BCTL > 0 */