dcm.c revision 1.44 1 1.44 thorpej /* $NetBSD: dcm.c,v 1.44 1998/03/28 23:49:06 thorpej Exp $ */
2 1.42 thorpej
3 1.42 thorpej /*-
4 1.42 thorpej * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
5 1.42 thorpej * All rights reserved.
6 1.42 thorpej *
7 1.42 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.42 thorpej * by Jason R. Thorpe.
9 1.42 thorpej *
10 1.42 thorpej * Redistribution and use in source and binary forms, with or without
11 1.42 thorpej * modification, are permitted provided that the following conditions
12 1.42 thorpej * are met:
13 1.42 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.42 thorpej * notice, this list of conditions and the following disclaimer.
15 1.42 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.42 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.42 thorpej * documentation and/or other materials provided with the distribution.
18 1.42 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.42 thorpej * must display the following acknowledgement:
20 1.42 thorpej * This product includes software developed by the NetBSD
21 1.42 thorpej * Foundation, Inc. and its contributors.
22 1.42 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.42 thorpej * contributors may be used to endorse or promote products derived
24 1.42 thorpej * from this software without specific prior written permission.
25 1.42 thorpej *
26 1.42 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.42 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.42 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.42 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.42 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.42 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.42 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.42 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.42 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.42 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.42 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.42 thorpej */
38 1.15 cgd
39 1.1 cgd /*
40 1.1 cgd * Copyright (c) 1988 University of Utah.
41 1.14 mycroft * Copyright (c) 1982, 1986, 1990, 1993
42 1.14 mycroft * The Regents of the University of California. All rights reserved.
43 1.1 cgd *
44 1.1 cgd * This code is derived from software contributed to Berkeley by
45 1.1 cgd * the Systems Programming Group of the University of Utah Computer
46 1.1 cgd * Science Department.
47 1.1 cgd *
48 1.1 cgd * Redistribution and use in source and binary forms, with or without
49 1.1 cgd * modification, are permitted provided that the following conditions
50 1.1 cgd * are met:
51 1.1 cgd * 1. Redistributions of source code must retain the above copyright
52 1.1 cgd * notice, this list of conditions and the following disclaimer.
53 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
54 1.1 cgd * notice, this list of conditions and the following disclaimer in the
55 1.1 cgd * documentation and/or other materials provided with the distribution.
56 1.1 cgd * 3. All advertising materials mentioning features or use of this software
57 1.1 cgd * must display the following acknowledgement:
58 1.1 cgd * This product includes software developed by the University of
59 1.1 cgd * California, Berkeley and its contributors.
60 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
61 1.1 cgd * may be used to endorse or promote products derived from this software
62 1.1 cgd * without specific prior written permission.
63 1.1 cgd *
64 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 1.1 cgd * SUCH DAMAGE.
75 1.1 cgd *
76 1.14 mycroft * from Utah: $Hdr: dcm.c 1.29 92/01/21$
77 1.14 mycroft *
78 1.15 cgd * @(#)dcm.c 8.4 (Berkeley) 1/12/94
79 1.1 cgd */
80 1.1 cgd
81 1.1 cgd /*
82 1.1 cgd * TODO:
83 1.1 cgd * Timeouts
84 1.1 cgd * Test console support.
85 1.1 cgd */
86 1.1 cgd
87 1.1 cgd /*
88 1.1 cgd * 98642/MUX
89 1.1 cgd */
90 1.13 mycroft #include <sys/param.h>
91 1.13 mycroft #include <sys/systm.h>
92 1.13 mycroft #include <sys/ioctl.h>
93 1.13 mycroft #include <sys/proc.h>
94 1.13 mycroft #include <sys/tty.h>
95 1.13 mycroft #include <sys/conf.h>
96 1.13 mycroft #include <sys/file.h>
97 1.13 mycroft #include <sys/uio.h>
98 1.13 mycroft #include <sys/kernel.h>
99 1.13 mycroft #include <sys/syslog.h>
100 1.13 mycroft #include <sys/time.h>
101 1.34 thorpej #include <sys/device.h>
102 1.13 mycroft
103 1.24 thorpej #include <machine/autoconf.h>
104 1.14 mycroft #include <machine/cpu.h>
105 1.39 thorpej #include <machine/intr.h>
106 1.14 mycroft
107 1.22 thorpej #include <dev/cons.h>
108 1.22 thorpej
109 1.34 thorpej #include <hp300/dev/dioreg.h>
110 1.34 thorpej #include <hp300/dev/diovar.h>
111 1.34 thorpej #include <hp300/dev/diodevs.h>
112 1.13 mycroft #include <hp300/dev/dcmreg.h>
113 1.1 cgd
114 1.1 cgd #ifndef DEFAULT_BAUD_RATE
115 1.1 cgd #define DEFAULT_BAUD_RATE 9600
116 1.1 cgd #endif
117 1.1 cgd
118 1.1 cgd struct speedtab dcmspeedtab[] = {
119 1.36 scottr { 0, BR_0 },
120 1.36 scottr { 50, BR_50 },
121 1.36 scottr { 75, BR_75 },
122 1.36 scottr { 110, BR_110 },
123 1.36 scottr { 134, BR_134 },
124 1.36 scottr { 150, BR_150 },
125 1.36 scottr { 300, BR_300 },
126 1.36 scottr { 600, BR_600 },
127 1.36 scottr { 1200, BR_1200 },
128 1.36 scottr { 1800, BR_1800 },
129 1.36 scottr { 2400, BR_2400 },
130 1.36 scottr { 4800, BR_4800 },
131 1.36 scottr { 9600, BR_9600 },
132 1.36 scottr { 19200, BR_19200 },
133 1.36 scottr { 38400, BR_38400 },
134 1.36 scottr { -1, -1 },
135 1.1 cgd };
136 1.1 cgd
137 1.1 cgd /* u-sec per character based on baudrate (assumes 1 start/8 data/1 stop bit) */
138 1.1 cgd #define DCM_USPERCH(s) (10000000 / (s))
139 1.1 cgd
140 1.1 cgd /*
141 1.1 cgd * Per board interrupt scheme. 16.7ms is the polling interrupt rate
142 1.1 cgd * (16.7ms is about 550 baud, 38.4k is 72 chars in 16.7ms).
143 1.1 cgd */
144 1.1 cgd #define DIS_TIMER 0
145 1.1 cgd #define DIS_PERCHAR 1
146 1.1 cgd #define DIS_RESET 2
147 1.1 cgd
148 1.1 cgd int dcmistype = -1; /* -1 == dynamic, 0 == timer, 1 == perchar */
149 1.1 cgd int dcminterval = 5; /* interval (secs) between checks */
150 1.1 cgd struct dcmischeme {
151 1.1 cgd int dis_perchar; /* non-zero if interrupting per char */
152 1.1 cgd long dis_time; /* last time examined */
153 1.1 cgd int dis_intr; /* recv interrupts during last interval */
154 1.1 cgd int dis_char; /* characters read during last interval */
155 1.20 thorpej };
156 1.1 cgd
157 1.1 cgd /*
158 1.22 thorpej * Stuff for DCM console support. This could probably be done a little
159 1.22 thorpej * better.
160 1.1 cgd */
161 1.22 thorpej static struct dcmdevice *dcm_cn = NULL; /* pointer to hardware */
162 1.22 thorpej static int dcmconsinit; /* has been initialized */
163 1.36 scottr /* static int dcm_lastcnpri = CN_DEAD; */ /* XXX last priority */
164 1.22 thorpej
165 1.1 cgd int dcmdefaultrate = DEFAULT_BAUD_RATE;
166 1.1 cgd int dcmconbrdbusy = 0;
167 1.1 cgd int dcmmajor;
168 1.1 cgd
169 1.1 cgd #ifdef KGDB
170 1.1 cgd /*
171 1.1 cgd * Kernel GDB support
172 1.1 cgd */
173 1.14 mycroft #include <machine/remote-sl.h>
174 1.1 cgd
175 1.1 cgd extern dev_t kgdb_dev;
176 1.1 cgd extern int kgdb_rate;
177 1.1 cgd extern int kgdb_debug_init;
178 1.1 cgd #endif
179 1.1 cgd
180 1.14 mycroft /* #define DCMSTATS */
181 1.1 cgd
182 1.1 cgd #ifdef DEBUG
183 1.1 cgd int dcmdebug = 0x0;
184 1.1 cgd #define DDB_SIOERR 0x01
185 1.1 cgd #define DDB_PARAM 0x02
186 1.1 cgd #define DDB_INPUT 0x04
187 1.1 cgd #define DDB_OUTPUT 0x08
188 1.1 cgd #define DDB_INTR 0x10
189 1.1 cgd #define DDB_IOCTL 0x20
190 1.1 cgd #define DDB_INTSCHM 0x40
191 1.1 cgd #define DDB_MODEM 0x80
192 1.1 cgd #define DDB_OPENCLOSE 0x100
193 1.1 cgd #endif
194 1.1 cgd
195 1.14 mycroft #ifdef DCMSTATS
196 1.1 cgd #define DCMRBSIZE 94
197 1.1 cgd #define DCMXBSIZE 24
198 1.1 cgd
199 1.1 cgd struct dcmstats {
200 1.1 cgd long xints; /* # of xmit ints */
201 1.1 cgd long xchars; /* # of xmit chars */
202 1.1 cgd long xempty; /* times outq is empty in dcmstart */
203 1.1 cgd long xrestarts; /* times completed while xmitting */
204 1.1 cgd long rints; /* # of recv ints */
205 1.1 cgd long rchars; /* # of recv chars */
206 1.1 cgd long xsilo[DCMXBSIZE+2]; /* times this many chars xmit on one int */
207 1.1 cgd long rsilo[DCMRBSIZE+2]; /* times this many chars read on one int */
208 1.20 thorpej };
209 1.1 cgd #endif
210 1.1 cgd
211 1.44 thorpej #define DCMUNIT(x) (minor(x) & 0x7ffff)
212 1.44 thorpej #define DCMDIALOUT(x) (minor(x) & 0x80000)
213 1.20 thorpej #define DCMBOARD(x) (((x) >> 2) & 0x3f)
214 1.20 thorpej #define DCMPORT(x) ((x) & 3)
215 1.1 cgd
216 1.1 cgd /*
217 1.1 cgd * Conversion from "HP DCE" to almost-normal DCE: on the 638 8-port mux,
218 1.1 cgd * the distribution panel uses "HP DCE" conventions. If requested via
219 1.1 cgd * the device flags, we swap the inputs to something closer to normal DCE,
220 1.1 cgd * allowing a straight-through cable to a DTE or a reversed cable
221 1.1 cgd * to a DCE (reversing 2-3, 4-5, 8-20 and leaving 6 unconnected;
222 1.1 cgd * this gets "DCD" on pin 20 and "CTS" on 4, but doesn't connect
223 1.1 cgd * DSR or make RTS work, though). The following gives the full
224 1.1 cgd * details of a cable from this mux panel to a modem:
225 1.1 cgd *
226 1.1 cgd * HP modem
227 1.1 cgd * name pin pin name
228 1.1 cgd * HP inputs:
229 1.1 cgd * "Rx" 2 3 Tx
230 1.1 cgd * CTS 4 5 CTS (only needed for CCTS_OFLOW)
231 1.1 cgd * DCD 20 8 DCD
232 1.1 cgd * "DSR" 9 6 DSR (unneeded)
233 1.1 cgd * RI 22 22 RI (unneeded)
234 1.1 cgd *
235 1.1 cgd * HP outputs:
236 1.1 cgd * "Tx" 3 2 Rx
237 1.1 cgd * "DTR" 6 not connected
238 1.1 cgd * "RTS" 8 20 DTR
239 1.1 cgd * "SR" 23 4 RTS (often not needed)
240 1.1 cgd */
241 1.1 cgd #define hp2dce_in(ibits) (iconv[(ibits) & 0xf])
242 1.1 cgd static char iconv[16] = {
243 1.1 cgd 0, MI_DM, MI_CTS, MI_CTS|MI_DM,
244 1.1 cgd MI_CD, MI_CD|MI_DM, MI_CD|MI_CTS, MI_CD|MI_CTS|MI_DM,
245 1.1 cgd MI_RI, MI_RI|MI_DM, MI_RI|MI_CTS, MI_RI|MI_CTS|MI_DM,
246 1.1 cgd MI_RI|MI_CD, MI_RI|MI_CD|MI_DM, MI_RI|MI_CD|MI_CTS,
247 1.1 cgd MI_RI|MI_CD|MI_CTS|MI_DM
248 1.1 cgd };
249 1.1 cgd
250 1.21 thorpej /*
251 1.21 thorpej * Note that 8-port boards appear as 2 4-port boards at consecutive
252 1.21 thorpej * select codes.
253 1.21 thorpej */
254 1.21 thorpej #define NDCMPORT 4
255 1.20 thorpej
256 1.20 thorpej struct dcm_softc {
257 1.34 thorpej struct device sc_dev; /* generic device glue */
258 1.20 thorpej struct dcmdevice *sc_dcm; /* pointer to hardware */
259 1.20 thorpej struct tty *sc_tty[NDCMPORT]; /* our tty instances */
260 1.20 thorpej struct modemreg *sc_modem[NDCMPORT]; /* modem control */
261 1.20 thorpej char sc_mcndlast[NDCMPORT]; /* XXX last modem status for port */
262 1.20 thorpej short sc_softCAR; /* mask of ports with soft-carrier */
263 1.20 thorpej struct dcmischeme sc_scheme; /* interrupt scheme for board */
264 1.20 thorpej
265 1.20 thorpej /*
266 1.20 thorpej * Mask of soft-carrier bits in config flags.
267 1.20 thorpej */
268 1.20 thorpej #define DCM_SOFTCAR 0x0000000f
269 1.20 thorpej
270 1.20 thorpej int sc_flags; /* misc. configuration info */
271 1.20 thorpej
272 1.20 thorpej /*
273 1.20 thorpej * Bits for sc_flags
274 1.20 thorpej */
275 1.20 thorpej #define DCM_ACTIVE 0x00000001 /* indicates board is alive */
276 1.24 thorpej #define DCM_ISCONSOLE 0x00000002 /* indicates board is console */
277 1.20 thorpej #define DCM_STDDCE 0x00000010 /* re-map DCE to standard */
278 1.20 thorpej #define DCM_FLAGMASK (DCM_STDDCE) /* mask of valid bits in config flags */
279 1.20 thorpej
280 1.20 thorpej #ifdef DCMSTATS
281 1.20 thorpej struct dcmstats sc_stats; /* metrics gathering */
282 1.20 thorpej #endif
283 1.34 thorpej };
284 1.34 thorpej
285 1.36 scottr cdev_decl(dcm);
286 1.20 thorpej
287 1.36 scottr int dcmintr __P((void *));
288 1.36 scottr void dcmpint __P((struct dcm_softc *, int, int));
289 1.36 scottr void dcmrint __P((struct dcm_softc *));
290 1.36 scottr void dcmreadbuf __P((struct dcm_softc *, int));
291 1.36 scottr void dcmxint __P((struct dcm_softc *, int));
292 1.36 scottr void dcmmint __P((struct dcm_softc *, int, int));
293 1.36 scottr
294 1.36 scottr int dcmparam __P((struct tty *, struct termios *));
295 1.36 scottr void dcmstart __P((struct tty *));
296 1.36 scottr void dcmstop __P((struct tty *, int));
297 1.36 scottr int dcmmctl __P((dev_t, int, int));
298 1.36 scottr void dcmsetischeme __P((int, int));
299 1.22 thorpej void dcminit __P((struct dcmdevice *, int, int));
300 1.22 thorpej
301 1.34 thorpej int dcmselftest __P((struct dcm_softc *));
302 1.34 thorpej
303 1.36 scottr int dcm_console_scan __P((int, caddr_t, void *));
304 1.36 scottr void dcmcnprobe __P((struct consdev *));
305 1.36 scottr void dcmcninit __P((struct consdev *));
306 1.36 scottr int dcmcngetc __P((dev_t));
307 1.36 scottr void dcmcnputc __P((dev_t, int));
308 1.36 scottr
309 1.38 scottr int dcmmatch __P((struct device *, struct cfdata *, void *));
310 1.38 scottr void dcmattach __P((struct device *, struct device *, void *));
311 1.38 scottr
312 1.38 scottr struct cfattach dcm_ca = {
313 1.38 scottr sizeof(struct dcm_softc), dcmmatch, dcmattach
314 1.38 scottr };
315 1.38 scottr
316 1.43 thorpej extern struct cfdriver dcm_cd;
317 1.38 scottr
318 1.34 thorpej int
319 1.34 thorpej dcmmatch(parent, match, aux)
320 1.34 thorpej struct device *parent;
321 1.34 thorpej struct cfdata *match;
322 1.34 thorpej void *aux;
323 1.34 thorpej {
324 1.34 thorpej struct dio_attach_args *da = aux;
325 1.34 thorpej
326 1.34 thorpej switch (da->da_id) {
327 1.34 thorpej case DIO_DEVICE_ID_DCM:
328 1.34 thorpej case DIO_DEVICE_ID_DCMREM:
329 1.34 thorpej return (1);
330 1.34 thorpej }
331 1.34 thorpej
332 1.34 thorpej return (0);
333 1.34 thorpej }
334 1.20 thorpej
335 1.34 thorpej void
336 1.34 thorpej dcmattach(parent, self, aux)
337 1.34 thorpej struct device *parent, *self;
338 1.34 thorpej void *aux;
339 1.34 thorpej {
340 1.34 thorpej struct dcm_softc *sc = (struct dcm_softc *)self;
341 1.34 thorpej struct dio_attach_args *da = aux;
342 1.34 thorpej struct dcmdevice *dcm;
343 1.34 thorpej int brd = self->dv_unit;
344 1.34 thorpej int scode = da->da_scode;
345 1.38 scottr int i, mbits, code, ipl;
346 1.20 thorpej
347 1.36 scottr sc->sc_flags = 0;
348 1.36 scottr
349 1.34 thorpej if (scode == conscode) {
350 1.34 thorpej dcm = (struct dcmdevice *)conaddr;
351 1.24 thorpej sc->sc_flags |= DCM_ISCONSOLE;
352 1.24 thorpej
353 1.24 thorpej /*
354 1.24 thorpej * We didn't know which unit this would be during
355 1.24 thorpej * the console probe, so we have to fixup cn_dev here.
356 1.24 thorpej * Note that we always assume port 1 on the board.
357 1.24 thorpej */
358 1.24 thorpej cn_tab->cn_dev = makedev(dcmmajor, (brd << 2) | DCMCONSPORT);
359 1.34 thorpej } else {
360 1.34 thorpej dcm = (struct dcmdevice *)iomap(dio_scodetopa(da->da_scode),
361 1.34 thorpej da->da_size);
362 1.34 thorpej if (dcm == NULL) {
363 1.34 thorpej printf("\n%s: can't map registers\n",
364 1.34 thorpej sc->sc_dev.dv_xname);
365 1.34 thorpej return;
366 1.34 thorpej }
367 1.34 thorpej }
368 1.34 thorpej
369 1.34 thorpej sc->sc_dcm = dcm;
370 1.34 thorpej
371 1.34 thorpej ipl = DIO_IPL(dcm);
372 1.34 thorpej printf(" ipl %d", ipl);
373 1.34 thorpej
374 1.38 scottr /*
375 1.38 scottr * XXX someone _should_ fix this; the self test screws
376 1.38 scottr * autoconfig messages.
377 1.38 scottr */
378 1.38 scottr if ((sc->sc_flags & DCM_ISCONSOLE) && dcmselftest(sc)) {
379 1.34 thorpej printf("\n%s: self-test failed\n", sc->sc_dev.dv_xname);
380 1.34 thorpej return;
381 1.24 thorpej }
382 1.20 thorpej
383 1.20 thorpej /* Extract configuration info from flags. */
384 1.34 thorpej sc->sc_softCAR = self->dv_cfdata->cf_flags & DCM_SOFTCAR;
385 1.36 scottr sc->sc_flags |= self->dv_cfdata->cf_flags & DCM_FLAGMASK;
386 1.20 thorpej
387 1.20 thorpej /* Mark our unit as configured. */
388 1.20 thorpej sc->sc_flags |= DCM_ACTIVE;
389 1.20 thorpej
390 1.20 thorpej /* Establish the interrupt handler. */
391 1.41 thorpej (void) dio_intr_establish(dcmintr, sc, ipl, IPL_TTY);
392 1.20 thorpej
393 1.1 cgd if (dcmistype == DIS_TIMER)
394 1.1 cgd dcmsetischeme(brd, DIS_RESET|DIS_TIMER);
395 1.1 cgd else
396 1.1 cgd dcmsetischeme(brd, DIS_RESET|DIS_PERCHAR);
397 1.1 cgd
398 1.1 cgd /* load pointers to modem control */
399 1.20 thorpej sc->sc_modem[0] = &dcm->dcm_modem0;
400 1.20 thorpej sc->sc_modem[1] = &dcm->dcm_modem1;
401 1.20 thorpej sc->sc_modem[2] = &dcm->dcm_modem2;
402 1.20 thorpej sc->sc_modem[3] = &dcm->dcm_modem3;
403 1.20 thorpej
404 1.1 cgd /* set DCD (modem) and CTS (flow control) on all ports */
405 1.20 thorpej if (sc->sc_flags & DCM_STDDCE)
406 1.1 cgd mbits = hp2dce_in(MI_CD|MI_CTS);
407 1.1 cgd else
408 1.1 cgd mbits = MI_CD|MI_CTS;
409 1.20 thorpej
410 1.20 thorpej for (i = 0; i < NDCMPORT; i++)
411 1.20 thorpej sc->sc_modem[i]->mdmmsk = mbits;
412 1.1 cgd
413 1.38 scottr /*
414 1.38 scottr * Get current state of mdmin register on all ports, so that
415 1.38 scottr * deltas will work properly.
416 1.38 scottr */
417 1.38 scottr for (i = 0; i < NDCMPORT; i++) {
418 1.38 scottr code = sc->sc_modem[i]->mdmin;
419 1.38 scottr if (sc->sc_flags & DCM_STDDCE)
420 1.38 scottr code = hp2dce_in(code);
421 1.38 scottr sc->sc_mcndlast[i] = code;
422 1.38 scottr }
423 1.38 scottr
424 1.1 cgd dcm->dcm_ic = IC_IE; /* turn all interrupts on */
425 1.20 thorpej
426 1.1 cgd /*
427 1.24 thorpej * Need to reset baud rate, etc. of next print so reset dcmconsinit.
428 1.1 cgd * Also make sure console is always "hardwired"
429 1.1 cgd */
430 1.24 thorpej if (sc->sc_flags & DCM_ISCONSOLE) {
431 1.1 cgd dcmconsinit = 0;
432 1.24 thorpej sc->sc_softCAR |= (1 << DCMCONSPORT);
433 1.31 christos printf(": console on port %d\n", DCMCONSPORT);
434 1.20 thorpej } else
435 1.31 christos printf("\n");
436 1.20 thorpej
437 1.20 thorpej #ifdef KGDB
438 1.20 thorpej if (major(kgdb_dev) == dcmmajor &&
439 1.20 thorpej DCMBOARD(DCMUNIT(kgdb_dev)) == brd) {
440 1.24 thorpej if (dcmconsole == DCMUNIT(kgdb_dev)) /* XXX fixme */
441 1.20 thorpej kgdb_dev = NODEV; /* can't debug over console port */
442 1.20 thorpej #ifndef KGDB_CHEAT
443 1.20 thorpej /*
444 1.20 thorpej * The following could potentially be replaced
445 1.20 thorpej * by the corresponding code in dcmcnprobe.
446 1.20 thorpej */
447 1.20 thorpej else {
448 1.22 thorpej dcminit(dcm, DCMPORT(DCMUNIT(kgdb_dev)),
449 1.22 thorpej kgdb_rate);
450 1.20 thorpej if (kgdb_debug_init) {
451 1.34 thorpej printf("%s port %d: ", sc->sc_dev.dv_xname,
452 1.20 thorpej DCMPORT(DCMUNIT(kgdb_dev)));
453 1.20 thorpej kgdb_connect(1);
454 1.20 thorpej } else
455 1.31 christos printf("%s port %d: kgdb enabled\n",
456 1.34 thorpej sc->sc_dev.dv_xname,
457 1.20 thorpej DCMPORT(DCMUNIT(kgdb_dev)));
458 1.20 thorpej }
459 1.20 thorpej /* end could be replaced */
460 1.34 thorpej #endif /* KGDB_CHEAT */
461 1.1 cgd }
462 1.34 thorpej #endif /* KGDB */
463 1.1 cgd }
464 1.1 cgd
465 1.1 cgd /* ARGSUSED */
466 1.17 mycroft int
467 1.1 cgd dcmopen(dev, flag, mode, p)
468 1.1 cgd dev_t dev;
469 1.1 cgd int flag, mode;
470 1.1 cgd struct proc *p;
471 1.1 cgd {
472 1.20 thorpej struct dcm_softc *sc;
473 1.20 thorpej struct tty *tp;
474 1.20 thorpej int unit, brd, port;
475 1.18 thorpej int error = 0, mbits, s;
476 1.1 cgd
477 1.20 thorpej unit = DCMUNIT(dev);
478 1.20 thorpej brd = DCMBOARD(unit);
479 1.20 thorpej port = DCMPORT(unit);
480 1.20 thorpej
481 1.34 thorpej if (brd >= dcm_cd.cd_ndevs || port >= NDCMPORT ||
482 1.34 thorpej (sc = dcm_cd.cd_devs[brd]) == NULL)
483 1.34 thorpej return (ENXIO);
484 1.20 thorpej
485 1.20 thorpej if ((sc->sc_flags & DCM_ACTIVE) == 0)
486 1.20 thorpej return (ENXIO);
487 1.20 thorpej
488 1.28 thorpej if (sc->sc_tty[port] == NULL) {
489 1.20 thorpej tp = sc->sc_tty[port] = ttymalloc();
490 1.28 thorpej tty_attach(tp);
491 1.28 thorpej } else
492 1.20 thorpej tp = sc->sc_tty[port];
493 1.20 thorpej
494 1.1 cgd tp->t_oproc = dcmstart;
495 1.1 cgd tp->t_param = dcmparam;
496 1.1 cgd tp->t_dev = dev;
497 1.18 thorpej
498 1.44 thorpej if ((tp->t_state & TS_ISOPEN) &&
499 1.44 thorpej (tp->t_state & TS_XCLUDE) &&
500 1.44 thorpej p->p_ucred->cr_uid != 0)
501 1.44 thorpej return (EBUSY);
502 1.44 thorpej
503 1.44 thorpej s = spltty();
504 1.44 thorpej
505 1.44 thorpej if ((tp->t_state & TS_ISOPEN) == 0 && tp->t_wopen == 0) {
506 1.18 thorpej /*
507 1.18 thorpej * Sanity clause: reset the card on first open.
508 1.18 thorpej * The card might be left in an inconsistent state
509 1.18 thorpej * if the card memory is read inadvertently.
510 1.18 thorpej */
511 1.22 thorpej dcminit(sc->sc_dcm, port, dcmdefaultrate);
512 1.18 thorpej
513 1.1 cgd ttychars(tp);
514 1.18 thorpej tp->t_iflag = TTYDEF_IFLAG;
515 1.18 thorpej tp->t_oflag = TTYDEF_OFLAG;
516 1.18 thorpej tp->t_cflag = TTYDEF_CFLAG;
517 1.18 thorpej tp->t_lflag = TTYDEF_LFLAG;
518 1.18 thorpej tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
519 1.18 thorpej
520 1.1 cgd (void) dcmparam(tp, &tp->t_termios);
521 1.1 cgd ttsetwater(tp);
522 1.18 thorpej
523 1.44 thorpej /* Set modem control state. */
524 1.44 thorpej mbits = MO_ON;
525 1.44 thorpej if (sc->sc_flags & DCM_STDDCE)
526 1.44 thorpej mbits |= MO_SR; /* pin 23, could be used as RTS */
527 1.44 thorpej
528 1.44 thorpej (void) dcmmctl(dev, mbits, DMSET); /* enable port */
529 1.20 thorpej
530 1.44 thorpej /* Set soft-carrier if so configured. */
531 1.44 thorpej if ((sc->sc_softCAR & (1 << port)) ||
532 1.44 thorpej (dcmmctl(dev, MO_OFF, DMGET) & MI_CD))
533 1.44 thorpej tp->t_state |= TS_CARR_ON;
534 1.44 thorpej }
535 1.18 thorpej
536 1.44 thorpej splx(s);
537 1.18 thorpej
538 1.1 cgd #ifdef DEBUG
539 1.1 cgd if (dcmdebug & DDB_MODEM)
540 1.31 christos printf("%s: dcmopen port %d softcarr %c\n",
541 1.34 thorpej sc->sc_dev.dv_xname, port,
542 1.20 thorpej (tp->t_state & TS_CARR_ON) ? '1' : '0');
543 1.1 cgd #endif
544 1.18 thorpej
545 1.44 thorpej error = ttyopen(tp, DCMDIALOUT(dev), (flag & O_NONBLOCK));
546 1.44 thorpej if (error)
547 1.44 thorpej goto bad;
548 1.1 cgd
549 1.1 cgd #ifdef DEBUG
550 1.1 cgd if (dcmdebug & DDB_OPENCLOSE)
551 1.31 christos printf("%s port %d: dcmopen: st %x fl %x\n",
552 1.34 thorpej sc->sc_dev.dv_xname, port, tp->t_state, tp->t_flags);
553 1.1 cgd #endif
554 1.44 thorpej error = (*linesw[tp->t_line].l_open)(dev, tp);
555 1.18 thorpej
556 1.44 thorpej bad:
557 1.1 cgd return (error);
558 1.1 cgd }
559 1.1 cgd
560 1.1 cgd /*ARGSUSED*/
561 1.17 mycroft int
562 1.1 cgd dcmclose(dev, flag, mode, p)
563 1.1 cgd dev_t dev;
564 1.1 cgd int flag, mode;
565 1.1 cgd struct proc *p;
566 1.1 cgd {
567 1.20 thorpej int s, unit, board, port;
568 1.20 thorpej struct dcm_softc *sc;
569 1.20 thorpej struct tty *tp;
570 1.1 cgd
571 1.20 thorpej unit = DCMUNIT(dev);
572 1.20 thorpej board = DCMBOARD(unit);
573 1.20 thorpej port = DCMPORT(unit);
574 1.20 thorpej
575 1.34 thorpej sc = dcm_cd.cd_devs[board];
576 1.20 thorpej tp = sc->sc_tty[port];
577 1.20 thorpej
578 1.1 cgd (*linesw[tp->t_line].l_close)(tp, flag);
579 1.18 thorpej
580 1.18 thorpej s = spltty();
581 1.18 thorpej
582 1.44 thorpej if (tp->t_cflag & HUPCL || tp->t_wopen != 0 ||
583 1.18 thorpej (tp->t_state & TS_ISOPEN) == 0)
584 1.1 cgd (void) dcmmctl(dev, MO_OFF, DMSET);
585 1.1 cgd #ifdef DEBUG
586 1.1 cgd if (dcmdebug & DDB_OPENCLOSE)
587 1.31 christos printf("%s port %d: dcmclose: st %x fl %x\n",
588 1.34 thorpej sc->sc_dev.dv_xname, port, tp->t_state, tp->t_flags);
589 1.1 cgd #endif
590 1.18 thorpej splx(s);
591 1.1 cgd ttyclose(tp);
592 1.12 mycroft #if 0
593 1.28 thorpej tty_detach(tp);
594 1.7 mycroft ttyfree(tp);
595 1.20 thorpej sc->sc_tty[port] == NULL;
596 1.12 mycroft #endif
597 1.1 cgd return (0);
598 1.1 cgd }
599 1.1 cgd
600 1.17 mycroft int
601 1.1 cgd dcmread(dev, uio, flag)
602 1.1 cgd dev_t dev;
603 1.1 cgd struct uio *uio;
604 1.14 mycroft int flag;
605 1.1 cgd {
606 1.20 thorpej int unit, board, port;
607 1.20 thorpej struct dcm_softc *sc;
608 1.36 scottr struct tty *tp;
609 1.20 thorpej
610 1.20 thorpej unit = DCMUNIT(dev);
611 1.20 thorpej board = DCMBOARD(unit);
612 1.20 thorpej port = DCMPORT(unit);
613 1.20 thorpej
614 1.34 thorpej sc = dcm_cd.cd_devs[board];
615 1.20 thorpej tp = sc->sc_tty[port];
616 1.14 mycroft
617 1.1 cgd return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
618 1.1 cgd }
619 1.1 cgd
620 1.17 mycroft int
621 1.1 cgd dcmwrite(dev, uio, flag)
622 1.1 cgd dev_t dev;
623 1.1 cgd struct uio *uio;
624 1.14 mycroft int flag;
625 1.1 cgd {
626 1.20 thorpej int unit, board, port;
627 1.20 thorpej struct dcm_softc *sc;
628 1.36 scottr struct tty *tp;
629 1.20 thorpej
630 1.20 thorpej unit = DCMUNIT(dev);
631 1.20 thorpej board = DCMBOARD(unit);
632 1.20 thorpej port = DCMPORT(unit);
633 1.20 thorpej
634 1.34 thorpej sc = dcm_cd.cd_devs[board];
635 1.20 thorpej tp = sc->sc_tty[port];
636 1.14 mycroft
637 1.1 cgd return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
638 1.1 cgd }
639 1.17 mycroft
640 1.17 mycroft struct tty *
641 1.17 mycroft dcmtty(dev)
642 1.17 mycroft dev_t dev;
643 1.17 mycroft {
644 1.20 thorpej int unit, board, port;
645 1.20 thorpej struct dcm_softc *sc;
646 1.17 mycroft
647 1.20 thorpej unit = DCMUNIT(dev);
648 1.20 thorpej board = DCMBOARD(unit);
649 1.20 thorpej port = DCMPORT(unit);
650 1.20 thorpej
651 1.34 thorpej sc = dcm_cd.cd_devs[board];
652 1.20 thorpej
653 1.20 thorpej return (sc->sc_tty[port]);
654 1.17 mycroft }
655 1.1 cgd
656 1.17 mycroft int
657 1.23 thorpej dcmintr(arg)
658 1.23 thorpej void *arg;
659 1.1 cgd {
660 1.23 thorpej struct dcm_softc *sc = arg;
661 1.20 thorpej struct dcmdevice *dcm = sc->sc_dcm;
662 1.20 thorpej struct dcmischeme *dis = &sc->sc_scheme;
663 1.34 thorpej int brd = sc->sc_dev.dv_unit;
664 1.20 thorpej int code, i;
665 1.1 cgd int pcnd[4], mcode, mcnd[4];
666 1.1 cgd
667 1.1 cgd /*
668 1.36 scottr * Do all guarded accesses right off to minimize
669 1.1 cgd * block out of hardware.
670 1.1 cgd */
671 1.1 cgd SEM_LOCK(dcm);
672 1.1 cgd if ((dcm->dcm_ic & IC_IR) == 0) {
673 1.1 cgd SEM_UNLOCK(dcm);
674 1.1 cgd return (0);
675 1.1 cgd }
676 1.1 cgd for (i = 0; i < 4; i++) {
677 1.1 cgd pcnd[i] = dcm->dcm_icrtab[i].dcm_data;
678 1.1 cgd dcm->dcm_icrtab[i].dcm_data = 0;
679 1.20 thorpej code = sc->sc_modem[i]->mdmin;
680 1.20 thorpej if (sc->sc_flags & DCM_STDDCE)
681 1.1 cgd code = hp2dce_in(code);
682 1.1 cgd mcnd[i] = code;
683 1.1 cgd }
684 1.1 cgd code = dcm->dcm_iir & IIR_MASK;
685 1.1 cgd dcm->dcm_iir = 0; /* XXX doc claims read clears interrupt?! */
686 1.1 cgd mcode = dcm->dcm_modemintr;
687 1.1 cgd dcm->dcm_modemintr = 0;
688 1.1 cgd SEM_UNLOCK(dcm);
689 1.1 cgd
690 1.1 cgd #ifdef DEBUG
691 1.1 cgd if (dcmdebug & DDB_INTR) {
692 1.31 christos printf("%s: dcmintr: iir %x pc %x/%x/%x/%x ",
693 1.34 thorpej sc->sc_dev.dv_xname, code, pcnd[0], pcnd[1],
694 1.20 thorpej pcnd[2], pcnd[3]);
695 1.31 christos printf("miir %x mc %x/%x/%x/%x\n",
696 1.1 cgd mcode, mcnd[0], mcnd[1], mcnd[2], mcnd[3]);
697 1.1 cgd }
698 1.1 cgd #endif
699 1.1 cgd if (code & IIR_TIMEO)
700 1.20 thorpej dcmrint(sc);
701 1.1 cgd if (code & IIR_PORT0)
702 1.20 thorpej dcmpint(sc, 0, pcnd[0]);
703 1.1 cgd if (code & IIR_PORT1)
704 1.20 thorpej dcmpint(sc, 1, pcnd[1]);
705 1.1 cgd if (code & IIR_PORT2)
706 1.20 thorpej dcmpint(sc, 2, pcnd[2]);
707 1.1 cgd if (code & IIR_PORT3)
708 1.20 thorpej dcmpint(sc, 3, pcnd[3]);
709 1.1 cgd if (code & IIR_MODM) {
710 1.1 cgd if (mcode == 0 || mcode & 0x1) /* mcode==0 -> 98642 board */
711 1.20 thorpej dcmmint(sc, 0, mcnd[0]);
712 1.1 cgd if (mcode & 0x2)
713 1.20 thorpej dcmmint(sc, 1, mcnd[1]);
714 1.1 cgd if (mcode & 0x4)
715 1.20 thorpej dcmmint(sc, 2, mcnd[2]);
716 1.1 cgd if (mcode & 0x8)
717 1.20 thorpej dcmmint(sc, 3, mcnd[3]);
718 1.1 cgd }
719 1.1 cgd
720 1.1 cgd /*
721 1.1 cgd * Chalk up a receiver interrupt if the timer running or one of
722 1.1 cgd * the ports reports a special character interrupt.
723 1.1 cgd */
724 1.1 cgd if ((code & IIR_TIMEO) ||
725 1.1 cgd ((pcnd[0]|pcnd[1]|pcnd[2]|pcnd[3]) & IT_SPEC))
726 1.1 cgd dis->dis_intr++;
727 1.1 cgd /*
728 1.1 cgd * See if it is time to check/change the interrupt rate.
729 1.1 cgd */
730 1.1 cgd if (dcmistype < 0 &&
731 1.1 cgd (i = time.tv_sec - dis->dis_time) >= dcminterval) {
732 1.1 cgd /*
733 1.1 cgd * If currently per-character and averaged over 70 interrupts
734 1.1 cgd * per-second (66 is threshold of 600 baud) in last interval,
735 1.1 cgd * switch to timer mode.
736 1.1 cgd *
737 1.1 cgd * XXX decay counts ala load average to avoid spikes?
738 1.1 cgd */
739 1.1 cgd if (dis->dis_perchar && dis->dis_intr > 70 * i)
740 1.1 cgd dcmsetischeme(brd, DIS_TIMER);
741 1.1 cgd /*
742 1.1 cgd * If currently using timer and had more interrupts than
743 1.1 cgd * received characters in the last interval, switch back
744 1.1 cgd * to per-character. Note that after changing to per-char
745 1.1 cgd * we must process any characters already in the queue
746 1.1 cgd * since they may have arrived before the bitmap was setup.
747 1.1 cgd *
748 1.1 cgd * XXX decay counts?
749 1.1 cgd */
750 1.1 cgd else if (!dis->dis_perchar && dis->dis_intr > dis->dis_char) {
751 1.1 cgd dcmsetischeme(brd, DIS_PERCHAR);
752 1.20 thorpej dcmrint(sc);
753 1.1 cgd }
754 1.1 cgd dis->dis_intr = dis->dis_char = 0;
755 1.1 cgd dis->dis_time = time.tv_sec;
756 1.1 cgd }
757 1.1 cgd return (1);
758 1.1 cgd }
759 1.1 cgd
760 1.1 cgd /*
761 1.1 cgd * Port interrupt. Can be two things:
762 1.1 cgd * First, it might be a special character (exception interrupt);
763 1.1 cgd * Second, it may be a buffer empty (transmit interrupt);
764 1.1 cgd */
765 1.36 scottr void
766 1.20 thorpej dcmpint(sc, port, code)
767 1.20 thorpej struct dcm_softc *sc;
768 1.20 thorpej int port, code;
769 1.1 cgd {
770 1.1 cgd
771 1.1 cgd if (code & IT_SPEC)
772 1.20 thorpej dcmreadbuf(sc, port);
773 1.1 cgd if (code & IT_TX)
774 1.20 thorpej dcmxint(sc, port);
775 1.1 cgd }
776 1.1 cgd
777 1.36 scottr void
778 1.20 thorpej dcmrint(sc)
779 1.20 thorpej struct dcm_softc *sc;
780 1.1 cgd {
781 1.20 thorpej int port;
782 1.1 cgd
783 1.20 thorpej for (port = 0; port < NDCMPORT; port++)
784 1.20 thorpej dcmreadbuf(sc, port);
785 1.1 cgd }
786 1.1 cgd
787 1.36 scottr void
788 1.20 thorpej dcmreadbuf(sc, port)
789 1.20 thorpej struct dcm_softc *sc;
790 1.20 thorpej int port;
791 1.1 cgd {
792 1.20 thorpej struct dcmdevice *dcm = sc->sc_dcm;
793 1.20 thorpej struct dcmpreg *pp = dcm_preg(dcm, port);
794 1.20 thorpej struct dcmrfifo *fifo;
795 1.38 scottr struct tty *tp;
796 1.20 thorpej int c, stat;
797 1.20 thorpej u_int head;
798 1.1 cgd int nch = 0;
799 1.14 mycroft #ifdef DCMSTATS
800 1.20 thorpej struct dcmstats *dsp = &sc->sc_stats;
801 1.1 cgd
802 1.1 cgd dsp->rints++;
803 1.1 cgd #endif
804 1.38 scottr tp = sc->sc_tty[port];
805 1.40 scottr if (tp == NULL)
806 1.38 scottr return;
807 1.38 scottr
808 1.1 cgd if ((tp->t_state & TS_ISOPEN) == 0) {
809 1.1 cgd #ifdef KGDB
810 1.20 thorpej if ((makedev(dcmmajor, minor(tp->t_dev)) == kgdb_dev) &&
811 1.1 cgd (head = pp->r_head & RX_MASK) != (pp->r_tail & RX_MASK) &&
812 1.14 mycroft dcm->dcm_rfifos[3-port][head>>1].data_char == FRAME_START) {
813 1.1 cgd pp->r_head = (head + 2) & RX_MASK;
814 1.1 cgd kgdb_connect(0); /* trap into kgdb */
815 1.1 cgd return;
816 1.1 cgd }
817 1.1 cgd #endif /* KGDB */
818 1.1 cgd pp->r_head = pp->r_tail & RX_MASK;
819 1.1 cgd return;
820 1.1 cgd }
821 1.1 cgd
822 1.1 cgd head = pp->r_head & RX_MASK;
823 1.1 cgd fifo = &dcm->dcm_rfifos[3-port][head>>1];
824 1.1 cgd /*
825 1.1 cgd * XXX upper bound on how many chars we will take in one swallow?
826 1.1 cgd */
827 1.1 cgd while (head != (pp->r_tail & RX_MASK)) {
828 1.1 cgd /*
829 1.1 cgd * Get character/status and update head pointer as fast
830 1.1 cgd * as possible to make room for more characters.
831 1.1 cgd */
832 1.1 cgd c = fifo->data_char;
833 1.1 cgd stat = fifo->data_stat;
834 1.1 cgd head = (head + 2) & RX_MASK;
835 1.1 cgd pp->r_head = head;
836 1.1 cgd fifo = head ? fifo+1 : &dcm->dcm_rfifos[3-port][0];
837 1.1 cgd nch++;
838 1.1 cgd
839 1.1 cgd #ifdef DEBUG
840 1.1 cgd if (dcmdebug & DDB_INPUT)
841 1.31 christos printf("%s port %d: dcmreadbuf: c%x('%c') s%x f%x h%x t%x\n",
842 1.34 thorpej sc->sc_dev.dv_xname, port,
843 1.20 thorpej c&0xFF, c, stat&0xFF,
844 1.1 cgd tp->t_flags, head, pp->r_tail);
845 1.1 cgd #endif
846 1.1 cgd /*
847 1.1 cgd * Check for and handle errors
848 1.1 cgd */
849 1.1 cgd if (stat & RD_MASK) {
850 1.1 cgd #ifdef DEBUG
851 1.1 cgd if (dcmdebug & (DDB_INPUT|DDB_SIOERR))
852 1.31 christos printf("%s port %d: dcmreadbuf: err: c%x('%c') s%x\n",
853 1.34 thorpej sc->sc_dev.dv_xname, port,
854 1.20 thorpej stat, c&0xFF, c);
855 1.1 cgd #endif
856 1.1 cgd if (stat & (RD_BD | RD_FE))
857 1.1 cgd c |= TTY_FE;
858 1.1 cgd else if (stat & RD_PE)
859 1.1 cgd c |= TTY_PE;
860 1.1 cgd else if (stat & RD_OVF)
861 1.1 cgd log(LOG_WARNING,
862 1.20 thorpej "%s port %d: silo overflow\n",
863 1.34 thorpej sc->sc_dev.dv_xname, port);
864 1.1 cgd else if (stat & RD_OE)
865 1.1 cgd log(LOG_WARNING,
866 1.20 thorpej "%s port %d: uart overflow\n",
867 1.34 thorpej sc->sc_dev.dv_xname, port);
868 1.1 cgd }
869 1.1 cgd (*linesw[tp->t_line].l_rint)(c, tp);
870 1.1 cgd }
871 1.20 thorpej sc->sc_scheme.dis_char += nch;
872 1.20 thorpej
873 1.14 mycroft #ifdef DCMSTATS
874 1.1 cgd dsp->rchars += nch;
875 1.1 cgd if (nch <= DCMRBSIZE)
876 1.1 cgd dsp->rsilo[nch]++;
877 1.1 cgd else
878 1.1 cgd dsp->rsilo[DCMRBSIZE+1]++;
879 1.1 cgd #endif
880 1.1 cgd }
881 1.1 cgd
882 1.36 scottr void
883 1.20 thorpej dcmxint(sc, port)
884 1.20 thorpej struct dcm_softc *sc;
885 1.20 thorpej int port;
886 1.1 cgd {
887 1.38 scottr struct tty *tp;
888 1.38 scottr
889 1.38 scottr tp = sc->sc_tty[port];
890 1.38 scottr if (tp == NULL || (tp->t_state & TS_ISOPEN) == 0)
891 1.38 scottr return;
892 1.20 thorpej
893 1.1 cgd tp->t_state &= ~TS_BUSY;
894 1.1 cgd if (tp->t_state & TS_FLUSH)
895 1.1 cgd tp->t_state &= ~TS_FLUSH;
896 1.1 cgd (*linesw[tp->t_line].l_start)(tp);
897 1.1 cgd }
898 1.1 cgd
899 1.36 scottr void
900 1.20 thorpej dcmmint(sc, port, mcnd)
901 1.20 thorpej struct dcm_softc *sc;
902 1.20 thorpej int port, mcnd;
903 1.1 cgd {
904 1.1 cgd int delta;
905 1.20 thorpej struct tty *tp;
906 1.20 thorpej struct dcmdevice *dcm = sc->sc_dcm;
907 1.20 thorpej
908 1.20 thorpej tp = sc->sc_tty[port];
909 1.38 scottr if (tp == NULL || (tp->t_state & TS_ISOPEN) == 0)
910 1.38 scottr return;
911 1.1 cgd
912 1.1 cgd #ifdef DEBUG
913 1.1 cgd if (dcmdebug & DDB_MODEM)
914 1.31 christos printf("%s port %d: dcmmint: mcnd %x mcndlast %x\n",
915 1.34 thorpej sc->sc_dev.dv_xname, port, mcnd, sc->sc_mcndlast[port]);
916 1.1 cgd #endif
917 1.20 thorpej delta = mcnd ^ sc->sc_mcndlast[port];
918 1.20 thorpej sc->sc_mcndlast[port] = mcnd;
919 1.1 cgd if ((delta & MI_CTS) && (tp->t_state & TS_ISOPEN) &&
920 1.1 cgd (tp->t_flags & CCTS_OFLOW)) {
921 1.1 cgd if (mcnd & MI_CTS) {
922 1.1 cgd tp->t_state &= ~TS_TTSTOP;
923 1.1 cgd ttstart(tp);
924 1.1 cgd } else
925 1.1 cgd tp->t_state |= TS_TTSTOP; /* inline dcmstop */
926 1.1 cgd }
927 1.1 cgd if (delta & MI_CD) {
928 1.1 cgd if (mcnd & MI_CD)
929 1.1 cgd (void)(*linesw[tp->t_line].l_modem)(tp, 1);
930 1.20 thorpej else if ((sc->sc_softCAR & (1 << port)) == 0 &&
931 1.1 cgd (*linesw[tp->t_line].l_modem)(tp, 0) == 0) {
932 1.20 thorpej sc->sc_modem[port]->mdmout = MO_OFF;
933 1.1 cgd SEM_LOCK(dcm);
934 1.20 thorpej dcm->dcm_modemchng |= (1 << port);
935 1.1 cgd dcm->dcm_cr |= CR_MODM;
936 1.1 cgd SEM_UNLOCK(dcm);
937 1.1 cgd DELAY(10); /* time to change lines */
938 1.1 cgd }
939 1.1 cgd }
940 1.1 cgd }
941 1.1 cgd
942 1.17 mycroft int
943 1.13 mycroft dcmioctl(dev, cmd, data, flag, p)
944 1.1 cgd dev_t dev;
945 1.36 scottr u_long cmd;
946 1.1 cgd caddr_t data;
947 1.13 mycroft int flag;
948 1.13 mycroft struct proc *p;
949 1.1 cgd {
950 1.20 thorpej struct dcm_softc *sc;
951 1.20 thorpej struct tty *tp;
952 1.20 thorpej struct dcmdevice *dcm;
953 1.20 thorpej int board, port, unit = DCMUNIT(dev);
954 1.1 cgd int error, s;
955 1.20 thorpej
956 1.20 thorpej port = DCMPORT(unit);
957 1.20 thorpej board = DCMBOARD(unit);
958 1.20 thorpej
959 1.34 thorpej sc = dcm_cd.cd_devs[board];
960 1.20 thorpej dcm = sc->sc_dcm;
961 1.20 thorpej tp = sc->sc_tty[port];
962 1.1 cgd
963 1.1 cgd #ifdef DEBUG
964 1.1 cgd if (dcmdebug & DDB_IOCTL)
965 1.37 scottr printf("%s port %d: dcmioctl: cmd %lx data %x flag %x\n",
966 1.34 thorpej sc->sc_dev.dv_xname, port, cmd, *data, flag);
967 1.1 cgd #endif
968 1.13 mycroft error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
969 1.1 cgd if (error >= 0)
970 1.1 cgd return (error);
971 1.13 mycroft error = ttioctl(tp, cmd, data, flag, p);
972 1.1 cgd if (error >= 0)
973 1.1 cgd return (error);
974 1.1 cgd
975 1.1 cgd switch (cmd) {
976 1.1 cgd case TIOCSBRK:
977 1.1 cgd /*
978 1.1 cgd * Wait for transmitter buffer to empty
979 1.1 cgd */
980 1.1 cgd s = spltty();
981 1.1 cgd while (dcm->dcm_thead[port].ptr != dcm->dcm_ttail[port].ptr)
982 1.1 cgd DELAY(DCM_USPERCH(tp->t_ospeed));
983 1.1 cgd SEM_LOCK(dcm);
984 1.1 cgd dcm->dcm_cmdtab[port].dcm_data |= CT_BRK;
985 1.1 cgd dcm->dcm_cr |= (1 << port); /* start break */
986 1.1 cgd SEM_UNLOCK(dcm);
987 1.1 cgd splx(s);
988 1.1 cgd break;
989 1.1 cgd
990 1.1 cgd case TIOCCBRK:
991 1.1 cgd SEM_LOCK(dcm);
992 1.1 cgd dcm->dcm_cmdtab[port].dcm_data |= CT_BRK;
993 1.1 cgd dcm->dcm_cr |= (1 << port); /* end break */
994 1.1 cgd SEM_UNLOCK(dcm);
995 1.1 cgd break;
996 1.1 cgd
997 1.1 cgd case TIOCSDTR:
998 1.1 cgd (void) dcmmctl(dev, MO_ON, DMBIS);
999 1.1 cgd break;
1000 1.1 cgd
1001 1.1 cgd case TIOCCDTR:
1002 1.1 cgd (void) dcmmctl(dev, MO_ON, DMBIC);
1003 1.1 cgd break;
1004 1.1 cgd
1005 1.1 cgd case TIOCMSET:
1006 1.1 cgd (void) dcmmctl(dev, *(int *)data, DMSET);
1007 1.1 cgd break;
1008 1.1 cgd
1009 1.1 cgd case TIOCMBIS:
1010 1.1 cgd (void) dcmmctl(dev, *(int *)data, DMBIS);
1011 1.1 cgd break;
1012 1.1 cgd
1013 1.1 cgd case TIOCMBIC:
1014 1.1 cgd (void) dcmmctl(dev, *(int *)data, DMBIC);
1015 1.1 cgd break;
1016 1.1 cgd
1017 1.1 cgd case TIOCMGET:
1018 1.1 cgd *(int *)data = dcmmctl(dev, 0, DMGET);
1019 1.1 cgd break;
1020 1.18 thorpej
1021 1.18 thorpej case TIOCGFLAGS: {
1022 1.18 thorpej int bits = 0;
1023 1.18 thorpej
1024 1.20 thorpej if ((sc->sc_softCAR & (1 << port)))
1025 1.18 thorpej bits |= TIOCFLAG_SOFTCAR;
1026 1.18 thorpej
1027 1.18 thorpej if (tp->t_cflag & CLOCAL)
1028 1.18 thorpej bits |= TIOCFLAG_CLOCAL;
1029 1.18 thorpej
1030 1.18 thorpej *(int *)data = bits;
1031 1.18 thorpej break;
1032 1.18 thorpej }
1033 1.18 thorpej
1034 1.18 thorpej case TIOCSFLAGS: {
1035 1.18 thorpej int userbits;
1036 1.18 thorpej
1037 1.18 thorpej error = suser(p->p_ucred, &p->p_acflag);
1038 1.18 thorpej if (error)
1039 1.18 thorpej return (EPERM);
1040 1.18 thorpej
1041 1.18 thorpej userbits = *(int *)data;
1042 1.18 thorpej
1043 1.18 thorpej if ((userbits & TIOCFLAG_SOFTCAR) ||
1044 1.24 thorpej ((sc->sc_flags & DCM_ISCONSOLE) &&
1045 1.24 thorpej (port == DCMCONSPORT)))
1046 1.20 thorpej sc->sc_softCAR |= (1 << port);
1047 1.18 thorpej
1048 1.18 thorpej if (userbits & TIOCFLAG_CLOCAL)
1049 1.18 thorpej tp->t_cflag |= CLOCAL;
1050 1.18 thorpej
1051 1.18 thorpej break;
1052 1.18 thorpej }
1053 1.1 cgd
1054 1.1 cgd default:
1055 1.1 cgd return (ENOTTY);
1056 1.1 cgd }
1057 1.1 cgd return (0);
1058 1.1 cgd }
1059 1.1 cgd
1060 1.17 mycroft int
1061 1.1 cgd dcmparam(tp, t)
1062 1.36 scottr struct tty *tp;
1063 1.36 scottr struct termios *t;
1064 1.1 cgd {
1065 1.20 thorpej struct dcm_softc *sc;
1066 1.20 thorpej struct dcmdevice *dcm;
1067 1.20 thorpej int unit, board, port, mode, cflag = t->c_cflag;
1068 1.1 cgd int ospeed = ttspeedtab(t->c_ospeed, dcmspeedtab);
1069 1.1 cgd
1070 1.20 thorpej unit = DCMUNIT(tp->t_dev);
1071 1.20 thorpej board = DCMBOARD(unit);
1072 1.20 thorpej port = DCMPORT(unit);
1073 1.20 thorpej
1074 1.34 thorpej sc = dcm_cd.cd_devs[board];
1075 1.20 thorpej dcm = sc->sc_dcm;
1076 1.20 thorpej
1077 1.1 cgd /* check requested parameters */
1078 1.1 cgd if (ospeed < 0 || (t->c_ispeed && t->c_ispeed != t->c_ospeed))
1079 1.1 cgd return (EINVAL);
1080 1.1 cgd /* and copy to tty */
1081 1.1 cgd tp->t_ispeed = t->c_ispeed;
1082 1.1 cgd tp->t_ospeed = t->c_ospeed;
1083 1.1 cgd tp->t_cflag = cflag;
1084 1.1 cgd if (ospeed == 0) {
1085 1.20 thorpej (void) dcmmctl(DCMUNIT(tp->t_dev), MO_OFF, DMSET);
1086 1.1 cgd return (0);
1087 1.1 cgd }
1088 1.1 cgd
1089 1.1 cgd mode = 0;
1090 1.1 cgd switch (cflag&CSIZE) {
1091 1.1 cgd case CS5:
1092 1.1 cgd mode = LC_5BITS; break;
1093 1.1 cgd case CS6:
1094 1.1 cgd mode = LC_6BITS; break;
1095 1.1 cgd case CS7:
1096 1.1 cgd mode = LC_7BITS; break;
1097 1.1 cgd case CS8:
1098 1.1 cgd mode = LC_8BITS; break;
1099 1.1 cgd }
1100 1.1 cgd if (cflag&PARENB) {
1101 1.1 cgd if (cflag&PARODD)
1102 1.1 cgd mode |= LC_PODD;
1103 1.1 cgd else
1104 1.1 cgd mode |= LC_PEVEN;
1105 1.1 cgd }
1106 1.1 cgd if (cflag&CSTOPB)
1107 1.1 cgd mode |= LC_2STOP;
1108 1.1 cgd else
1109 1.1 cgd mode |= LC_1STOP;
1110 1.1 cgd #ifdef DEBUG
1111 1.1 cgd if (dcmdebug & DDB_PARAM)
1112 1.31 christos printf("%s port %d: dcmparam: cflag %x mode %x speed %d uperch %d\n",
1113 1.34 thorpej sc->sc_dev.dv_xname, port, cflag, mode, tp->t_ospeed,
1114 1.1 cgd DCM_USPERCH(tp->t_ospeed));
1115 1.1 cgd #endif
1116 1.1 cgd
1117 1.1 cgd /*
1118 1.1 cgd * Wait for transmitter buffer to empty.
1119 1.1 cgd */
1120 1.1 cgd while (dcm->dcm_thead[port].ptr != dcm->dcm_ttail[port].ptr)
1121 1.1 cgd DELAY(DCM_USPERCH(tp->t_ospeed));
1122 1.1 cgd /*
1123 1.1 cgd * Make changes known to hardware.
1124 1.1 cgd */
1125 1.1 cgd dcm->dcm_data[port].dcm_baud = ospeed;
1126 1.1 cgd dcm->dcm_data[port].dcm_conf = mode;
1127 1.1 cgd SEM_LOCK(dcm);
1128 1.1 cgd dcm->dcm_cmdtab[port].dcm_data |= CT_CON;
1129 1.1 cgd dcm->dcm_cr |= (1 << port);
1130 1.1 cgd SEM_UNLOCK(dcm);
1131 1.1 cgd /*
1132 1.1 cgd * Delay for config change to take place. Weighted by baud.
1133 1.1 cgd * XXX why do we do this?
1134 1.1 cgd */
1135 1.1 cgd DELAY(16 * DCM_USPERCH(tp->t_ospeed));
1136 1.1 cgd return (0);
1137 1.1 cgd }
1138 1.1 cgd
1139 1.9 deraadt void
1140 1.1 cgd dcmstart(tp)
1141 1.36 scottr struct tty *tp;
1142 1.1 cgd {
1143 1.20 thorpej struct dcm_softc *sc;
1144 1.20 thorpej struct dcmdevice *dcm;
1145 1.20 thorpej struct dcmpreg *pp;
1146 1.20 thorpej struct dcmtfifo *fifo;
1147 1.20 thorpej char *bp;
1148 1.20 thorpej u_int head, tail, next;
1149 1.20 thorpej int unit, board, port, nch;
1150 1.1 cgd char buf[16];
1151 1.1 cgd int s;
1152 1.14 mycroft #ifdef DCMSTATS
1153 1.20 thorpej struct dcmstats *dsp = &sc->sc_stats;
1154 1.1 cgd int tch = 0;
1155 1.1 cgd #endif
1156 1.1 cgd
1157 1.20 thorpej unit = DCMUNIT(tp->t_dev);
1158 1.20 thorpej board = DCMBOARD(unit);
1159 1.20 thorpej port = DCMPORT(unit);
1160 1.20 thorpej
1161 1.34 thorpej sc = dcm_cd.cd_devs[board];
1162 1.20 thorpej dcm = sc->sc_dcm;
1163 1.20 thorpej
1164 1.1 cgd s = spltty();
1165 1.14 mycroft #ifdef DCMSTATS
1166 1.1 cgd dsp->xints++;
1167 1.1 cgd #endif
1168 1.1 cgd #ifdef DEBUG
1169 1.1 cgd if (dcmdebug & DDB_OUTPUT)
1170 1.31 christos printf("%s port %d: dcmstart: state %x flags %x outcc %d\n",
1171 1.34 thorpej sc->sc_dev.dv_xname, port, tp->t_state, tp->t_flags,
1172 1.7 mycroft tp->t_outq.c_cc);
1173 1.1 cgd #endif
1174 1.1 cgd if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
1175 1.1 cgd goto out;
1176 1.7 mycroft if (tp->t_outq.c_cc <= tp->t_lowat) {
1177 1.1 cgd if (tp->t_state&TS_ASLEEP) {
1178 1.1 cgd tp->t_state &= ~TS_ASLEEP;
1179 1.7 mycroft wakeup((caddr_t)&tp->t_outq);
1180 1.1 cgd }
1181 1.2 cgd selwakeup(&tp->t_wsel);
1182 1.1 cgd }
1183 1.7 mycroft if (tp->t_outq.c_cc == 0) {
1184 1.14 mycroft #ifdef DCMSTATS
1185 1.1 cgd dsp->xempty++;
1186 1.1 cgd #endif
1187 1.1 cgd goto out;
1188 1.1 cgd }
1189 1.1 cgd
1190 1.1 cgd pp = dcm_preg(dcm, port);
1191 1.1 cgd tail = pp->t_tail & TX_MASK;
1192 1.1 cgd next = (tail + 1) & TX_MASK;
1193 1.1 cgd head = pp->t_head & TX_MASK;
1194 1.1 cgd if (head == next)
1195 1.1 cgd goto out;
1196 1.1 cgd fifo = &dcm->dcm_tfifos[3-port][tail];
1197 1.1 cgd again:
1198 1.1 cgd nch = q_to_b(&tp->t_outq, buf, (head - next) & TX_MASK);
1199 1.14 mycroft #ifdef DCMSTATS
1200 1.1 cgd tch += nch;
1201 1.1 cgd #endif
1202 1.1 cgd #ifdef DEBUG
1203 1.1 cgd if (dcmdebug & DDB_OUTPUT)
1204 1.31 christos printf("\thead %x tail %x nch %d\n", head, tail, nch);
1205 1.1 cgd #endif
1206 1.1 cgd /*
1207 1.1 cgd * Loop transmitting all the characters we can.
1208 1.1 cgd */
1209 1.1 cgd for (bp = buf; --nch >= 0; bp++) {
1210 1.1 cgd fifo->data_char = *bp;
1211 1.1 cgd pp->t_tail = next;
1212 1.1 cgd /*
1213 1.1 cgd * If this is the first character,
1214 1.1 cgd * get the hardware moving right now.
1215 1.1 cgd */
1216 1.1 cgd if (bp == buf) {
1217 1.1 cgd tp->t_state |= TS_BUSY;
1218 1.1 cgd SEM_LOCK(dcm);
1219 1.1 cgd dcm->dcm_cmdtab[port].dcm_data |= CT_TX;
1220 1.1 cgd dcm->dcm_cr |= (1 << port);
1221 1.1 cgd SEM_UNLOCK(dcm);
1222 1.1 cgd }
1223 1.1 cgd tail = next;
1224 1.1 cgd fifo = tail ? fifo+1 : &dcm->dcm_tfifos[3-port][0];
1225 1.1 cgd next = (next + 1) & TX_MASK;
1226 1.1 cgd }
1227 1.1 cgd /*
1228 1.1 cgd * Head changed while we were loading the buffer,
1229 1.1 cgd * go back and load some more if we can.
1230 1.1 cgd */
1231 1.7 mycroft if (tp->t_outq.c_cc && head != (pp->t_head & TX_MASK)) {
1232 1.14 mycroft #ifdef DCMSTATS
1233 1.1 cgd dsp->xrestarts++;
1234 1.1 cgd #endif
1235 1.1 cgd head = pp->t_head & TX_MASK;
1236 1.1 cgd goto again;
1237 1.1 cgd }
1238 1.1 cgd
1239 1.1 cgd /*
1240 1.1 cgd * Kick it one last time in case it finished while we were
1241 1.1 cgd * loading the last bunch.
1242 1.1 cgd */
1243 1.1 cgd if (bp > &buf[1]) {
1244 1.1 cgd tp->t_state |= TS_BUSY;
1245 1.1 cgd SEM_LOCK(dcm);
1246 1.1 cgd dcm->dcm_cmdtab[port].dcm_data |= CT_TX;
1247 1.1 cgd dcm->dcm_cr |= (1 << port);
1248 1.1 cgd SEM_UNLOCK(dcm);
1249 1.1 cgd }
1250 1.1 cgd #ifdef DEBUG
1251 1.1 cgd if (dcmdebug & DDB_INTR)
1252 1.37 scottr printf("%s port %d: dcmstart: head %x tail %x outqcc %d\n",
1253 1.34 thorpej sc->sc_dev.dv_xname, port, head, tail, tp->t_outq.c_cc);
1254 1.1 cgd #endif
1255 1.1 cgd out:
1256 1.14 mycroft #ifdef DCMSTATS
1257 1.1 cgd dsp->xchars += tch;
1258 1.1 cgd if (tch <= DCMXBSIZE)
1259 1.1 cgd dsp->xsilo[tch]++;
1260 1.1 cgd else
1261 1.1 cgd dsp->xsilo[DCMXBSIZE+1]++;
1262 1.1 cgd #endif
1263 1.1 cgd splx(s);
1264 1.1 cgd }
1265 1.1 cgd
1266 1.1 cgd /*
1267 1.1 cgd * Stop output on a line.
1268 1.1 cgd */
1269 1.29 mycroft void
1270 1.1 cgd dcmstop(tp, flag)
1271 1.36 scottr struct tty *tp;
1272 1.14 mycroft int flag;
1273 1.1 cgd {
1274 1.1 cgd int s;
1275 1.1 cgd
1276 1.1 cgd s = spltty();
1277 1.1 cgd if (tp->t_state & TS_BUSY) {
1278 1.1 cgd /* XXX is there some way to safely stop transmission? */
1279 1.1 cgd if ((tp->t_state&TS_TTSTOP) == 0)
1280 1.1 cgd tp->t_state |= TS_FLUSH;
1281 1.1 cgd }
1282 1.1 cgd splx(s);
1283 1.1 cgd }
1284 1.1 cgd
1285 1.1 cgd /*
1286 1.1 cgd * Modem control
1287 1.1 cgd */
1288 1.36 scottr int
1289 1.1 cgd dcmmctl(dev, bits, how)
1290 1.1 cgd dev_t dev;
1291 1.1 cgd int bits, how;
1292 1.1 cgd {
1293 1.20 thorpej struct dcm_softc *sc;
1294 1.20 thorpej struct dcmdevice *dcm;
1295 1.20 thorpej int s, unit, brd, port, hit = 0;
1296 1.20 thorpej
1297 1.20 thorpej unit = DCMUNIT(dev);
1298 1.20 thorpej brd = DCMBOARD(unit);
1299 1.20 thorpej port = DCMPORT(unit);
1300 1.34 thorpej
1301 1.34 thorpej sc = dcm_cd.cd_devs[brd];
1302 1.20 thorpej dcm = sc->sc_dcm;
1303 1.1 cgd
1304 1.1 cgd #ifdef DEBUG
1305 1.1 cgd if (dcmdebug & DDB_MODEM)
1306 1.31 christos printf("%s port %d: dcmmctl: bits 0x%x how %x\n",
1307 1.34 thorpej sc->sc_dev.dv_xname, port, bits, how);
1308 1.1 cgd #endif
1309 1.1 cgd
1310 1.1 cgd s = spltty();
1311 1.20 thorpej
1312 1.1 cgd switch (how) {
1313 1.1 cgd case DMSET:
1314 1.20 thorpej sc->sc_modem[port]->mdmout = bits;
1315 1.1 cgd hit++;
1316 1.1 cgd break;
1317 1.1 cgd
1318 1.1 cgd case DMBIS:
1319 1.20 thorpej sc->sc_modem[port]->mdmout |= bits;
1320 1.1 cgd hit++;
1321 1.1 cgd break;
1322 1.1 cgd
1323 1.1 cgd case DMBIC:
1324 1.20 thorpej sc->sc_modem[port]->mdmout &= ~bits;
1325 1.1 cgd hit++;
1326 1.1 cgd break;
1327 1.1 cgd
1328 1.1 cgd case DMGET:
1329 1.20 thorpej bits = sc->sc_modem[port]->mdmin;
1330 1.20 thorpej if (sc->sc_flags & DCM_STDDCE)
1331 1.1 cgd bits = hp2dce_in(bits);
1332 1.1 cgd break;
1333 1.1 cgd }
1334 1.1 cgd if (hit) {
1335 1.1 cgd SEM_LOCK(dcm);
1336 1.1 cgd dcm->dcm_modemchng |= 1<<(unit & 3);
1337 1.1 cgd dcm->dcm_cr |= CR_MODM;
1338 1.1 cgd SEM_UNLOCK(dcm);
1339 1.1 cgd DELAY(10); /* delay until done */
1340 1.1 cgd (void) splx(s);
1341 1.1 cgd }
1342 1.1 cgd return (bits);
1343 1.1 cgd }
1344 1.1 cgd
1345 1.1 cgd /*
1346 1.1 cgd * Set board to either interrupt per-character or at a fixed interval.
1347 1.1 cgd */
1348 1.36 scottr void
1349 1.1 cgd dcmsetischeme(brd, flags)
1350 1.1 cgd int brd, flags;
1351 1.1 cgd {
1352 1.34 thorpej struct dcm_softc *sc = dcm_cd.cd_devs[brd];
1353 1.20 thorpej struct dcmdevice *dcm = sc->sc_dcm;
1354 1.20 thorpej struct dcmischeme *dis = &sc->sc_scheme;
1355 1.20 thorpej int i;
1356 1.1 cgd u_char mask;
1357 1.1 cgd int perchar = flags & DIS_PERCHAR;
1358 1.1 cgd
1359 1.1 cgd #ifdef DEBUG
1360 1.1 cgd if (dcmdebug & DDB_INTSCHM)
1361 1.31 christos printf("%s: dcmsetischeme(%d): cur %d, ints %d, chars %d\n",
1362 1.34 thorpej sc->sc_dev.dv_xname, perchar, dis->dis_perchar,
1363 1.1 cgd dis->dis_intr, dis->dis_char);
1364 1.1 cgd if ((flags & DIS_RESET) == 0 && perchar == dis->dis_perchar) {
1365 1.31 christos printf("%s: dcmsetischeme: redundent request %d\n",
1366 1.34 thorpej sc->sc_dev.dv_xname, perchar);
1367 1.1 cgd return;
1368 1.1 cgd }
1369 1.1 cgd #endif
1370 1.1 cgd /*
1371 1.1 cgd * If perchar is non-zero, we enable interrupts on all characters
1372 1.1 cgd * otherwise we disable perchar interrupts and use periodic
1373 1.1 cgd * polling interrupts.
1374 1.1 cgd */
1375 1.1 cgd dis->dis_perchar = perchar;
1376 1.1 cgd mask = perchar ? 0xf : 0x0;
1377 1.1 cgd for (i = 0; i < 256; i++)
1378 1.1 cgd dcm->dcm_bmap[i].data_data = mask;
1379 1.1 cgd /*
1380 1.1 cgd * Don't slow down tandem mode, interrupt on flow control
1381 1.1 cgd * chars for any port on the board.
1382 1.1 cgd */
1383 1.1 cgd if (!perchar) {
1384 1.36 scottr struct tty *tp;
1385 1.1 cgd int c;
1386 1.1 cgd
1387 1.20 thorpej for (i = 0; i < NDCMPORT; i++) {
1388 1.20 thorpej tp = sc->sc_tty[i];
1389 1.20 thorpej
1390 1.1 cgd if ((c = tp->t_cc[VSTART]) != _POSIX_VDISABLE)
1391 1.1 cgd dcm->dcm_bmap[c].data_data |= (1 << i);
1392 1.1 cgd if ((c = tp->t_cc[VSTOP]) != _POSIX_VDISABLE)
1393 1.1 cgd dcm->dcm_bmap[c].data_data |= (1 << i);
1394 1.1 cgd }
1395 1.1 cgd }
1396 1.1 cgd /*
1397 1.1 cgd * Board starts with timer disabled so if first call is to
1398 1.1 cgd * set perchar mode then we don't want to toggle the timer.
1399 1.1 cgd */
1400 1.1 cgd if (flags == (DIS_RESET|DIS_PERCHAR))
1401 1.1 cgd return;
1402 1.1 cgd /*
1403 1.1 cgd * Toggle card 16.7ms interrupts (we first make sure that card
1404 1.1 cgd * has cleared the bit so it will see the toggle).
1405 1.1 cgd */
1406 1.1 cgd while (dcm->dcm_cr & CR_TIMER)
1407 1.1 cgd ;
1408 1.1 cgd SEM_LOCK(dcm);
1409 1.1 cgd dcm->dcm_cr |= CR_TIMER;
1410 1.1 cgd SEM_UNLOCK(dcm);
1411 1.1 cgd }
1412 1.1 cgd
1413 1.22 thorpej void
1414 1.22 thorpej dcminit(dcm, port, rate)
1415 1.22 thorpej struct dcmdevice *dcm;
1416 1.22 thorpej int port, rate;
1417 1.22 thorpej {
1418 1.22 thorpej int s, mode;
1419 1.22 thorpej
1420 1.22 thorpej mode = LC_8BITS | LC_1STOP;
1421 1.22 thorpej
1422 1.22 thorpej s = splhigh();
1423 1.22 thorpej
1424 1.22 thorpej /*
1425 1.22 thorpej * Wait for transmitter buffer to empty.
1426 1.22 thorpej */
1427 1.22 thorpej while (dcm->dcm_thead[port].ptr != dcm->dcm_ttail[port].ptr)
1428 1.22 thorpej DELAY(DCM_USPERCH(rate));
1429 1.22 thorpej
1430 1.22 thorpej /*
1431 1.22 thorpej * Make changes known to hardware.
1432 1.22 thorpej */
1433 1.22 thorpej dcm->dcm_data[port].dcm_baud = ttspeedtab(rate, dcmspeedtab);
1434 1.22 thorpej dcm->dcm_data[port].dcm_conf = mode;
1435 1.22 thorpej SEM_LOCK(dcm);
1436 1.22 thorpej dcm->dcm_cmdtab[port].dcm_data |= CT_CON;
1437 1.22 thorpej dcm->dcm_cr |= (1 << port);
1438 1.22 thorpej SEM_UNLOCK(dcm);
1439 1.22 thorpej
1440 1.22 thorpej /*
1441 1.22 thorpej * Delay for config change to take place. Weighted by baud.
1442 1.22 thorpej * XXX why do we do this?
1443 1.22 thorpej */
1444 1.22 thorpej DELAY(16 * DCM_USPERCH(rate));
1445 1.22 thorpej splx(s);
1446 1.22 thorpej }
1447 1.22 thorpej
1448 1.1 cgd /*
1449 1.34 thorpej * Empirically derived self-test magic
1450 1.34 thorpej */
1451 1.34 thorpej int
1452 1.34 thorpej dcmselftest(sc)
1453 1.34 thorpej struct dcm_softc *sc;
1454 1.34 thorpej {
1455 1.34 thorpej struct dcmdevice *dcm = sc->sc_dcm;
1456 1.36 scottr int timo = 0;
1457 1.36 scottr int s, rv;
1458 1.34 thorpej
1459 1.35 thorpej rv = 1;
1460 1.35 thorpej
1461 1.35 thorpej s = splhigh();
1462 1.34 thorpej dcm->dcm_rsid = DCMRS;
1463 1.34 thorpej DELAY(50000); /* 5000 is not long enough */
1464 1.34 thorpej dcm->dcm_rsid = 0;
1465 1.34 thorpej dcm->dcm_ic = IC_IE;
1466 1.34 thorpej dcm->dcm_cr = CR_SELFT;
1467 1.35 thorpej while ((dcm->dcm_ic & IC_IR) == 0) {
1468 1.34 thorpej if (++timo == 20000)
1469 1.35 thorpej goto out;
1470 1.35 thorpej DELAY(1);
1471 1.35 thorpej }
1472 1.34 thorpej DELAY(50000); /* XXX why is this needed ???? */
1473 1.35 thorpej while ((dcm->dcm_iir & IIR_SELFT) == 0) {
1474 1.34 thorpej if (++timo == 400000)
1475 1.35 thorpej goto out;
1476 1.35 thorpej DELAY(1);
1477 1.35 thorpej }
1478 1.34 thorpej DELAY(50000); /* XXX why is this needed ???? */
1479 1.34 thorpej if (dcm->dcm_stcon != ST_OK) {
1480 1.34 thorpej #if 0
1481 1.34 thorpej if (hd->hp_args->hw_sc != conscode)
1482 1.34 thorpej printf("dcm%d: self test failed: %x\n",
1483 1.34 thorpej brd, dcm->dcm_stcon);
1484 1.34 thorpej #endif
1485 1.35 thorpej goto out;
1486 1.34 thorpej }
1487 1.34 thorpej dcm->dcm_ic = IC_ID;
1488 1.35 thorpej rv = 0;
1489 1.35 thorpej
1490 1.35 thorpej out:
1491 1.34 thorpej splx(s);
1492 1.35 thorpej return (rv);
1493 1.34 thorpej }
1494 1.34 thorpej
1495 1.34 thorpej /*
1496 1.1 cgd * Following are all routines needed for DCM to act as console
1497 1.1 cgd */
1498 1.1 cgd
1499 1.24 thorpej int
1500 1.24 thorpej dcm_console_scan(scode, va, arg)
1501 1.24 thorpej int scode;
1502 1.24 thorpej caddr_t va;
1503 1.24 thorpej void *arg;
1504 1.1 cgd {
1505 1.24 thorpej struct dcmdevice *dcm = (struct dcmdevice *)va;
1506 1.24 thorpej struct consdev *cp = arg;
1507 1.24 thorpej u_char *dioiidev;
1508 1.25 thorpej int force = 0, pri;
1509 1.1 cgd
1510 1.20 thorpej switch (dcm->dcm_rsid) {
1511 1.1 cgd case DCMID:
1512 1.25 thorpej pri = CN_NORMAL;
1513 1.1 cgd break;
1514 1.20 thorpej
1515 1.1 cgd case DCMID|DCMCON:
1516 1.25 thorpej pri = CN_REMOTE;
1517 1.1 cgd break;
1518 1.20 thorpej
1519 1.1 cgd default:
1520 1.24 thorpej return (0);
1521 1.1 cgd }
1522 1.20 thorpej
1523 1.24 thorpej #ifdef CONSCODE
1524 1.1 cgd /*
1525 1.24 thorpej * Raise our priority, if appropriate.
1526 1.1 cgd */
1527 1.24 thorpej if (scode == CONSCODE) {
1528 1.25 thorpej pri = CN_REMOTE;
1529 1.24 thorpej force = conforced = 1;
1530 1.24 thorpej }
1531 1.24 thorpej #endif
1532 1.22 thorpej
1533 1.26 thorpej /* Only raise priority. */
1534 1.26 thorpej if (pri > cp->cn_pri)
1535 1.26 thorpej cp->cn_pri = pri;
1536 1.26 thorpej
1537 1.22 thorpej /*
1538 1.22 thorpej * If our priority is higher than the currently-remembered
1539 1.24 thorpej * console, stash our priority, for the benefit of dcmcninit().
1540 1.22 thorpej */
1541 1.26 thorpej if (((cn_tab == NULL) || (cp->cn_pri > cn_tab->cn_pri)) || force) {
1542 1.26 thorpej cn_tab = cp;
1543 1.24 thorpej if (scode >= 132) {
1544 1.24 thorpej dioiidev = (u_char *)va;
1545 1.24 thorpej return ((dioiidev[0x101] + 1) * 0x100000);
1546 1.24 thorpej }
1547 1.24 thorpej return (DIOCSIZE);
1548 1.22 thorpej }
1549 1.24 thorpej return (0);
1550 1.24 thorpej }
1551 1.24 thorpej
1552 1.24 thorpej void
1553 1.24 thorpej dcmcnprobe(cp)
1554 1.24 thorpej struct consdev *cp;
1555 1.24 thorpej {
1556 1.24 thorpej
1557 1.24 thorpej /* locate the major number */
1558 1.24 thorpej for (dcmmajor = 0; dcmmajor < nchrdev; dcmmajor++)
1559 1.24 thorpej if (cdevsw[dcmmajor].d_open == dcmopen)
1560 1.24 thorpej break;
1561 1.24 thorpej
1562 1.24 thorpej /* initialize required fields */
1563 1.24 thorpej cp->cn_dev = makedev(dcmmajor, 0); /* XXX */
1564 1.24 thorpej cp->cn_pri = CN_DEAD;
1565 1.24 thorpej
1566 1.24 thorpej /* Abort early if console already forced. */
1567 1.24 thorpej if (conforced)
1568 1.24 thorpej return;
1569 1.24 thorpej
1570 1.24 thorpej console_scan(dcm_console_scan, cp);
1571 1.22 thorpej
1572 1.1 cgd #ifdef KGDB_CHEAT
1573 1.24 thorpej /* XXX this needs to be fixed. */
1574 1.1 cgd /*
1575 1.1 cgd * This doesn't currently work, at least not with ite consoles;
1576 1.1 cgd * the console hasn't been initialized yet.
1577 1.1 cgd */
1578 1.20 thorpej if (major(kgdb_dev) == dcmmajor &&
1579 1.20 thorpej DCMBOARD(DCMUNIT(kgdb_dev)) == DCMBOARD(unit)) {
1580 1.22 thorpej dcminit(dcm_cn, DCMPORT(DCMUNIT(kgdb_dev)), kgdb_rate);
1581 1.1 cgd if (kgdb_debug_init) {
1582 1.1 cgd /*
1583 1.1 cgd * We assume that console is ready for us...
1584 1.1 cgd * this assumes that a dca or ite console
1585 1.1 cgd * has been selected already and will init
1586 1.1 cgd * on the first putc.
1587 1.1 cgd */
1588 1.31 christos printf("dcm%d: ", DCMUNIT(kgdb_dev));
1589 1.1 cgd kgdb_connect(1);
1590 1.1 cgd }
1591 1.1 cgd }
1592 1.1 cgd #endif
1593 1.1 cgd }
1594 1.1 cgd
1595 1.24 thorpej /* ARGSUSED */
1596 1.16 mycroft void
1597 1.1 cgd dcmcninit(cp)
1598 1.1 cgd struct consdev *cp;
1599 1.1 cgd {
1600 1.20 thorpej
1601 1.24 thorpej dcm_cn = (struct dcmdevice *)conaddr;
1602 1.24 thorpej dcminit(dcm_cn, DCMCONSPORT, dcmdefaultrate);
1603 1.1 cgd dcmconsinit = 1;
1604 1.1 cgd }
1605 1.1 cgd
1606 1.24 thorpej /* ARGSUSED */
1607 1.17 mycroft int
1608 1.1 cgd dcmcngetc(dev)
1609 1.1 cgd dev_t dev;
1610 1.1 cgd {
1611 1.20 thorpej struct dcmrfifo *fifo;
1612 1.20 thorpej struct dcmpreg *pp;
1613 1.20 thorpej u_int head;
1614 1.24 thorpej int s, c, stat;
1615 1.22 thorpej
1616 1.24 thorpej pp = dcm_preg(dcm_cn, DCMCONSPORT);
1617 1.20 thorpej
1618 1.1 cgd s = splhigh();
1619 1.1 cgd head = pp->r_head & RX_MASK;
1620 1.24 thorpej fifo = &dcm_cn->dcm_rfifos[3-DCMCONSPORT][head>>1];
1621 1.1 cgd while (head == (pp->r_tail & RX_MASK))
1622 1.1 cgd ;
1623 1.1 cgd /*
1624 1.1 cgd * If board interrupts are enabled, just let our received char
1625 1.1 cgd * interrupt through in case some other port on the board was
1626 1.1 cgd * busy. Otherwise we must clear the interrupt.
1627 1.1 cgd */
1628 1.22 thorpej SEM_LOCK(dcm_cn);
1629 1.22 thorpej if ((dcm_cn->dcm_ic & IC_IE) == 0)
1630 1.22 thorpej stat = dcm_cn->dcm_iir;
1631 1.22 thorpej SEM_UNLOCK(dcm_cn);
1632 1.1 cgd c = fifo->data_char;
1633 1.1 cgd stat = fifo->data_stat;
1634 1.1 cgd pp->r_head = (head + 2) & RX_MASK;
1635 1.1 cgd splx(s);
1636 1.1 cgd return (c);
1637 1.1 cgd }
1638 1.1 cgd
1639 1.1 cgd /*
1640 1.1 cgd * Console kernel output character routine.
1641 1.1 cgd */
1642 1.24 thorpej /* ARGSUSED */
1643 1.16 mycroft void
1644 1.1 cgd dcmcnputc(dev, c)
1645 1.1 cgd dev_t dev;
1646 1.1 cgd int c;
1647 1.1 cgd {
1648 1.20 thorpej struct dcmpreg *pp;
1649 1.1 cgd unsigned tail;
1650 1.36 scottr int s, stat;
1651 1.22 thorpej
1652 1.24 thorpej pp = dcm_preg(dcm_cn, DCMCONSPORT);
1653 1.20 thorpej
1654 1.1 cgd s = splhigh();
1655 1.1 cgd #ifdef KGDB
1656 1.1 cgd if (dev != kgdb_dev)
1657 1.1 cgd #endif
1658 1.1 cgd if (dcmconsinit == 0) {
1659 1.24 thorpej dcminit(dcm_cn, DCMCONSPORT, dcmdefaultrate);
1660 1.1 cgd dcmconsinit = 1;
1661 1.1 cgd }
1662 1.1 cgd tail = pp->t_tail & TX_MASK;
1663 1.1 cgd while (tail != (pp->t_head & TX_MASK))
1664 1.1 cgd ;
1665 1.24 thorpej dcm_cn->dcm_tfifos[3-DCMCONSPORT][tail].data_char = c;
1666 1.1 cgd pp->t_tail = tail = (tail + 1) & TX_MASK;
1667 1.22 thorpej SEM_LOCK(dcm_cn);
1668 1.24 thorpej dcm_cn->dcm_cmdtab[DCMCONSPORT].dcm_data |= CT_TX;
1669 1.24 thorpej dcm_cn->dcm_cr |= (1 << DCMCONSPORT);
1670 1.22 thorpej SEM_UNLOCK(dcm_cn);
1671 1.1 cgd while (tail != (pp->t_head & TX_MASK))
1672 1.1 cgd ;
1673 1.1 cgd /*
1674 1.1 cgd * If board interrupts are enabled, just let our completion
1675 1.1 cgd * interrupt through in case some other port on the board
1676 1.1 cgd * was busy. Otherwise we must clear the interrupt.
1677 1.1 cgd */
1678 1.22 thorpej if ((dcm_cn->dcm_ic & IC_IE) == 0) {
1679 1.22 thorpej SEM_LOCK(dcm_cn);
1680 1.22 thorpej stat = dcm_cn->dcm_iir;
1681 1.22 thorpej SEM_UNLOCK(dcm_cn);
1682 1.1 cgd }
1683 1.1 cgd splx(s);
1684 1.1 cgd }
1685