dz.c revision 1.23 1 /* $NetBSD: dz.c,v 1.23 2006/10/01 19:28:43 elad Exp $ */
2 /*
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Ralph Campbell and Rick Macklem.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 /*
35 * Copyright (c) 1996 Ken C. Wellsch. All rights reserved.
36 *
37 * This code is derived from software contributed to Berkeley by
38 * Ralph Campbell and Rick Macklem.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by the University of
51 * California, Berkeley and its contributors.
52 * 4. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * SUCH DAMAGE.
67 */
68
69 #include <sys/cdefs.h>
70 __KERNEL_RCSID(0, "$NetBSD: dz.c,v 1.23 2006/10/01 19:28:43 elad Exp $");
71
72 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <sys/callout.h>
75 #include <sys/ioctl.h>
76 #include <sys/tty.h>
77 #include <sys/proc.h>
78 #include <sys/buf.h>
79 #include <sys/conf.h>
80 #include <sys/file.h>
81 #include <sys/uio.h>
82 #include <sys/kernel.h>
83 #include <sys/syslog.h>
84 #include <sys/device.h>
85 #include <sys/kauth.h>
86
87 #include <machine/bus.h>
88
89 #include <dev/dec/dzreg.h>
90 #include <dev/dec/dzvar.h>
91
92 #include <dev/cons.h>
93
94 #define DZ_READ_BYTE(adr) \
95 bus_space_read_1(sc->sc_iot, sc->sc_ioh, sc->sc_dr.adr)
96 #define DZ_READ_WORD(adr) \
97 bus_space_read_2(sc->sc_iot, sc->sc_ioh, sc->sc_dr.adr)
98 #define DZ_WRITE_BYTE(adr, val) \
99 bus_space_write_1(sc->sc_iot, sc->sc_ioh, sc->sc_dr.adr, val)
100 #define DZ_WRITE_WORD(adr, val) \
101 bus_space_write_2(sc->sc_iot, sc->sc_ioh, sc->sc_dr.adr, val)
102 #define DZ_BARRIER() \
103 bus_space_barrier(sc->sc_iot, sc->sc_ioh, sc->sc_dr.dr_firstreg, \
104 sc->sc_dr.dr_winsize, \
105 BUS_SPACE_BARRIER_WRITE | BUS_SPACE_BARRIER_READ)
106
107 #include "ioconf.h"
108
109 /* Flags used to monitor modem bits, make them understood outside driver */
110
111 #define DML_DTR TIOCM_DTR
112 #define DML_DCD TIOCM_CD
113 #define DML_RI TIOCM_RI
114 #define DML_BRK 0100000 /* no equivalent, we will mask */
115
116 static const struct speedtab dzspeedtab[] =
117 {
118 { 0, 0 },
119 { 50, DZ_LPR_B50 },
120 { 75, DZ_LPR_B75 },
121 { 110, DZ_LPR_B110 },
122 { 134, DZ_LPR_B134 },
123 { 150, DZ_LPR_B150 },
124 { 300, DZ_LPR_B300 },
125 { 600, DZ_LPR_B600 },
126 { 1200, DZ_LPR_B1200 },
127 { 1800, DZ_LPR_B1800 },
128 { 2000, DZ_LPR_B2000 },
129 { 2400, DZ_LPR_B2400 },
130 { 3600, DZ_LPR_B3600 },
131 { 4800, DZ_LPR_B4800 },
132 { 7200, DZ_LPR_B7200 },
133 { 9600, DZ_LPR_B9600 },
134 { 19200, DZ_LPR_B19200 },
135 { -1, -1 }
136 };
137
138 static void dzstart(struct tty *);
139 static int dzparam(struct tty *, struct termios *);
140 static unsigned dzmctl(struct dz_softc *, int, int, int);
141 static void dzscan(void *);
142
143 dev_type_open(dzopen);
144 dev_type_close(dzclose);
145 dev_type_read(dzread);
146 dev_type_write(dzwrite);
147 dev_type_ioctl(dzioctl);
148 dev_type_stop(dzstop);
149 dev_type_tty(dztty);
150 dev_type_poll(dzpoll);
151
152 const struct cdevsw dz_cdevsw = {
153 dzopen, dzclose, dzread, dzwrite, dzioctl,
154 dzstop, dztty, dzpoll, nommap, ttykqfilter, D_TTY
155 };
156
157 /*
158 * The DZ series doesn't interrupt on carrier transitions,
159 * so we have to use a timer to watch it.
160 */
161 int dz_timer; /* true if timer started */
162 struct callout dzscan_ch;
163 static struct cnm_state dz_cnm_state;
164
165 void
166 dzattach(struct dz_softc *sc, struct evcnt *parent_evcnt, int consline)
167 {
168 int n;
169
170 sc->sc_rxint = sc->sc_brk = 0;
171 sc->sc_consline = consline;
172
173 sc->sc_dr.dr_tcrw = sc->sc_dr.dr_tcr;
174 DZ_WRITE_WORD(dr_csr, DZ_CSR_MSE | DZ_CSR_RXIE | DZ_CSR_TXIE);
175 DZ_WRITE_BYTE(dr_dtr, 0);
176 DZ_WRITE_BYTE(dr_break, 0);
177 DZ_BARRIER();
178
179 /* Initialize our softc structure. Should be done in open? */
180
181 for (n = 0; n < sc->sc_type; n++) {
182 sc->sc_dz[n].dz_sc = sc;
183 sc->sc_dz[n].dz_line = n;
184 sc->sc_dz[n].dz_tty = ttymalloc();
185 }
186
187 evcnt_attach_dynamic(&sc->sc_rintrcnt, EVCNT_TYPE_INTR, parent_evcnt,
188 sc->sc_dev.dv_xname, "rintr");
189 evcnt_attach_dynamic(&sc->sc_tintrcnt, EVCNT_TYPE_INTR, parent_evcnt,
190 sc->sc_dev.dv_xname, "tintr");
191
192 /* Console magic keys */
193 cn_init_magic(&dz_cnm_state);
194 cn_set_magic("\047\001"); /* default magic is BREAK */
195 /* VAX will change it in MD code */
196
197 /* Alas no interrupt on modem bit changes, so we manually scan */
198
199 if (dz_timer == 0) {
200 dz_timer = 1;
201 callout_init(&dzscan_ch);
202 callout_reset(&dzscan_ch, hz, dzscan, NULL);
203 }
204 printf("\n");
205 }
206
207 /* Receiver Interrupt */
208
209 void
210 dzrint(void *arg)
211 {
212 struct dz_softc *sc = arg;
213 struct tty *tp;
214 int cc, mcc, line;
215 unsigned c;
216 int overrun = 0;
217
218 sc->sc_rxint++;
219
220 while ((c = DZ_READ_WORD(dr_rbuf)) & DZ_RBUF_DATA_VALID) {
221 cc = c & 0xFF;
222 line = DZ_PORT(c>>8);
223 tp = sc->sc_dz[line].dz_tty;
224
225 /* Must be caught early */
226 if (sc->sc_dz[line].dz_catch &&
227 (*sc->sc_dz[line].dz_catch)(sc->sc_dz[line].dz_private, cc))
228 continue;
229
230 if ((c & (DZ_RBUF_FRAMING_ERR | 0xff)) == DZ_RBUF_FRAMING_ERR)
231 mcc = CNC_BREAK;
232 else
233 mcc = cc;
234
235 cn_check_magic(tp->t_dev, mcc, dz_cnm_state);
236
237 if (!(tp->t_state & TS_ISOPEN)) {
238 wakeup((caddr_t)&tp->t_rawq);
239 continue;
240 }
241
242 if ((c & DZ_RBUF_OVERRUN_ERR) && overrun == 0) {
243 log(LOG_WARNING, "%s: silo overflow, line %d\n",
244 sc->sc_dev.dv_xname, line);
245 overrun = 1;
246 }
247
248 if (c & DZ_RBUF_FRAMING_ERR)
249 cc |= TTY_FE;
250 if (c & DZ_RBUF_PARITY_ERR)
251 cc |= TTY_PE;
252
253 (*tp->t_linesw->l_rint)(cc, tp);
254 }
255 }
256
257 /* Transmitter Interrupt */
258
259 void
260 dzxint(void *arg)
261 {
262 struct dz_softc *sc = arg;
263 struct tty *tp;
264 struct clist *cl;
265 int line, ch, csr;
266 u_char tcr;
267
268 /*
269 * Switch to POLLED mode.
270 * Some simple measurements indicated that even on
271 * one port, by freeing the scanner in the controller
272 * by either providing a character or turning off
273 * the port when output is complete, the transmitter
274 * was ready to accept more output when polled again.
275 * With just two ports running the game "worms,"
276 * almost every interrupt serviced both transmitters!
277 * Each UART is double buffered, so if the scanner
278 * is quick enough and timing works out, we can even
279 * feed the same port twice.
280 *
281 * Ragge 980517:
282 * Do not need to turn off interrupts, already at interrupt level.
283 * Remove the pdma stuff; no great need of it right now.
284 */
285
286 while (((csr = DZ_READ_WORD(dr_csr)) & DZ_CSR_TX_READY) != 0) {
287
288 line = DZ_PORT(csr>>8);
289
290 tp = sc->sc_dz[line].dz_tty;
291 cl = &tp->t_outq;
292 tp->t_state &= ~TS_BUSY;
293
294 /* Just send out a char if we have one */
295 /* As long as we can fill the chip buffer, we just loop here */
296 if (cl->c_cc) {
297 tp->t_state |= TS_BUSY;
298 ch = getc(cl);
299 DZ_WRITE_BYTE(dr_tbuf, ch);
300 DZ_BARRIER();
301 continue;
302 }
303 /* Nothing to send; clear the scan bit */
304 /* Clear xmit scanner bit; dzstart may set it again */
305 tcr = DZ_READ_WORD(dr_tcrw);
306 tcr &= 255;
307 tcr &= ~(1 << line);
308 DZ_WRITE_BYTE(dr_tcr, tcr);
309 DZ_BARRIER();
310 if (sc->sc_dz[line].dz_catch)
311 continue;
312
313 if (tp->t_state & TS_FLUSH)
314 tp->t_state &= ~TS_FLUSH;
315 else
316 ndflush (&tp->t_outq, cl->c_cc);
317
318 (*tp->t_linesw->l_start)(tp);
319 }
320 }
321
322 int
323 dzopen(dev_t dev, int flag, int mode, struct lwp *l)
324 {
325 struct tty *tp;
326 int unit, line;
327 struct dz_softc *sc;
328 int s, error = 0;
329
330 unit = DZ_I2C(minor(dev));
331 line = DZ_PORT(minor(dev));
332 if (unit >= dz_cd.cd_ndevs || dz_cd.cd_devs[unit] == NULL)
333 return (ENXIO);
334
335 sc = dz_cd.cd_devs[unit];
336
337 if (line >= sc->sc_type)
338 return ENXIO;
339
340 /* if some other device is using the line, it's busy */
341 if (sc->sc_dz[line].dz_catch)
342 return EBUSY;
343
344 tp = sc->sc_dz[line].dz_tty;
345 if (tp == NULL)
346 return (ENODEV);
347 tp->t_oproc = dzstart;
348 tp->t_param = dzparam;
349 tp->t_dev = dev;
350
351 if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
352 return (EBUSY);
353
354 if ((tp->t_state & TS_ISOPEN) == 0) {
355 ttychars(tp);
356 if (tp->t_ispeed == 0) {
357 tp->t_iflag = TTYDEF_IFLAG;
358 tp->t_oflag = TTYDEF_OFLAG;
359 tp->t_cflag = TTYDEF_CFLAG;
360 tp->t_lflag = TTYDEF_LFLAG;
361 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
362 }
363 (void) dzparam(tp, &tp->t_termios);
364 ttsetwater(tp);
365 /* Use DMBIS and *not* DMSET or else we clobber incoming bits */
366 if (dzmctl(sc, line, DML_DTR, DMBIS) & DML_DCD)
367 tp->t_state |= TS_CARR_ON;
368 s = spltty();
369 while (!(flag & O_NONBLOCK) && !(tp->t_cflag & CLOCAL) &&
370 !(tp->t_state & TS_CARR_ON)) {
371 tp->t_wopen++;
372 error = ttysleep(tp, (caddr_t)&tp->t_rawq,
373 TTIPRI | PCATCH, ttopen, 0);
374 tp->t_wopen--;
375 if (error)
376 break;
377 }
378 (void) splx(s);
379 if (error)
380 return (error);
381 return ((*tp->t_linesw->l_open)(dev, tp));
382 }
383
384 /*ARGSUSED*/
385 int
386 dzclose(dev_t dev, int flag, int mode, struct lwp *l)
387 {
388 struct dz_softc *sc;
389 struct tty *tp;
390 int unit, line;
391
392
393 unit = DZ_I2C(minor(dev));
394 line = DZ_PORT(minor(dev));
395 sc = dz_cd.cd_devs[unit];
396
397 tp = sc->sc_dz[line].dz_tty;
398
399 (*tp->t_linesw->l_close)(tp, flag);
400
401 /* Make sure a BREAK state is not left enabled. */
402 (void) dzmctl(sc, line, DML_BRK, DMBIC);
403
404 /* Do a hangup if so required. */
405 if ((tp->t_cflag & HUPCL) || tp->t_wopen || !(tp->t_state & TS_ISOPEN))
406 (void) dzmctl(sc, line, 0, DMSET);
407
408 return (ttyclose(tp));
409 }
410
411 int
412 dzread(dev_t dev, struct uio *uio, int flag)
413 {
414 struct tty *tp;
415 struct dz_softc *sc;
416
417 sc = dz_cd.cd_devs[DZ_I2C(minor(dev))];
418
419 tp = sc->sc_dz[DZ_PORT(minor(dev))].dz_tty;
420 return ((*tp->t_linesw->l_read)(tp, uio, flag));
421 }
422
423 int
424 dzwrite(dev_t dev, struct uio *uio, int flag)
425 {
426 struct tty *tp;
427 struct dz_softc *sc;
428
429 sc = dz_cd.cd_devs[DZ_I2C(minor(dev))];
430
431 tp = sc->sc_dz[DZ_PORT(minor(dev))].dz_tty;
432 return ((*tp->t_linesw->l_write)(tp, uio, flag));
433 }
434
435 int
436 dzpoll(dev, events, l)
437 dev_t dev;
438 int events;
439 struct lwp *l;
440 {
441 struct tty *tp;
442 struct dz_softc *sc;
443
444 sc = dz_cd.cd_devs[DZ_I2C(minor(dev))];
445
446 tp = sc->sc_dz[DZ_PORT(minor(dev))].dz_tty;
447 return ((*tp->t_linesw->l_poll)(tp, events, l));
448 }
449
450 /*ARGSUSED*/
451 int
452 dzioctl(dev_t dev, u_long cmd, caddr_t data, int flag, struct lwp *l)
453 {
454 struct dz_softc *sc;
455 struct tty *tp;
456 int unit, line;
457 int error;
458
459 unit = DZ_I2C(minor(dev));
460 line = DZ_PORT(minor(dev));
461 sc = dz_cd.cd_devs[unit];
462 tp = sc->sc_dz[line].dz_tty;
463
464 error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, l);
465 if (error >= 0)
466 return (error);
467
468 error = ttioctl(tp, cmd, data, flag, l);
469 if (error >= 0)
470 return (error);
471
472 switch (cmd) {
473
474 case TIOCSBRK:
475 (void) dzmctl(sc, line, DML_BRK, DMBIS);
476 break;
477
478 case TIOCCBRK:
479 (void) dzmctl(sc, line, DML_BRK, DMBIC);
480 break;
481
482 case TIOCSDTR:
483 (void) dzmctl(sc, line, DML_DTR, DMBIS);
484 break;
485
486 case TIOCCDTR:
487 (void) dzmctl(sc, line, DML_DTR, DMBIC);
488 break;
489
490 case TIOCMSET:
491 (void) dzmctl(sc, line, *(int *)data, DMSET);
492 break;
493
494 case TIOCMBIS:
495 (void) dzmctl(sc, line, *(int *)data, DMBIS);
496 break;
497
498 case TIOCMBIC:
499 (void) dzmctl(sc, line, *(int *)data, DMBIC);
500 break;
501
502 case TIOCMGET:
503 *(int *)data = (dzmctl(sc, line, 0, DMGET) & ~DML_BRK);
504 break;
505
506 default:
507 return (EPASSTHROUGH);
508 }
509 return (0);
510 }
511
512 struct tty *
513 dztty(dev_t dev)
514 {
515 struct dz_softc *sc = dz_cd.cd_devs[DZ_I2C(minor(dev))];
516 struct tty *tp = sc->sc_dz[DZ_PORT(minor(dev))].dz_tty;
517
518 return (tp);
519 }
520
521 /*ARGSUSED*/
522 void
523 dzstop(struct tty *tp, int flag)
524 {
525 if (tp->t_state & TS_BUSY)
526 if (!(tp->t_state & TS_TTSTOP))
527 tp->t_state |= TS_FLUSH;
528 }
529
530 void
531 dzstart(struct tty *tp)
532 {
533 struct dz_softc *sc;
534 struct clist *cl;
535 int unit, line, s;
536 char state;
537
538 unit = DZ_I2C(minor(tp->t_dev));
539 line = DZ_PORT(minor(tp->t_dev));
540 sc = dz_cd.cd_devs[unit];
541
542 s = spltty();
543 if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP)) {
544 splx(s);
545 return;
546 }
547 cl = &tp->t_outq;
548 if (cl->c_cc <= tp->t_lowat) {
549 if (tp->t_state & TS_ASLEEP) {
550 tp->t_state &= ~TS_ASLEEP;
551 wakeup((caddr_t)cl);
552 }
553 selwakeup(&tp->t_wsel);
554 }
555 if (cl->c_cc == 0) {
556 splx(s);
557 return;
558 }
559
560 tp->t_state |= TS_BUSY;
561
562 state = DZ_READ_WORD(dr_tcrw) & 255;
563 if ((state & (1 << line)) == 0) {
564 DZ_WRITE_BYTE(dr_tcr, state | (1 << line));
565 DZ_BARRIER();
566 }
567 dzxint(sc);
568 splx(s);
569 }
570
571 static int
572 dzparam(struct tty *tp, struct termios *t)
573 {
574 struct dz_softc *sc;
575 int cflag = t->c_cflag;
576 int unit, line;
577 int ispeed = ttspeedtab(t->c_ispeed, dzspeedtab);
578 int ospeed = ttspeedtab(t->c_ospeed, dzspeedtab);
579 unsigned lpr;
580 int s;
581
582 unit = DZ_I2C(minor(tp->t_dev));
583 line = DZ_PORT(minor(tp->t_dev));
584 sc = dz_cd.cd_devs[unit];
585
586 /* check requested parameters */
587 if (ospeed < 0 || ispeed < 0 || ispeed != ospeed)
588 return (EINVAL);
589
590 tp->t_ispeed = t->c_ispeed;
591 tp->t_ospeed = t->c_ospeed;
592 tp->t_cflag = cflag;
593
594 if (ospeed == 0) {
595 (void) dzmctl(sc, line, 0, DMSET); /* hang up line */
596 return (0);
597 }
598
599 s = spltty();
600
601 lpr = DZ_LPR_RX_ENABLE | ((ispeed&0xF)<<8) | line;
602
603 switch (cflag & CSIZE)
604 {
605 case CS5:
606 lpr |= DZ_LPR_5_BIT_CHAR;
607 break;
608 case CS6:
609 lpr |= DZ_LPR_6_BIT_CHAR;
610 break;
611 case CS7:
612 lpr |= DZ_LPR_7_BIT_CHAR;
613 break;
614 default:
615 lpr |= DZ_LPR_8_BIT_CHAR;
616 break;
617 }
618 if (cflag & PARENB)
619 lpr |= DZ_LPR_PARENB;
620 if (cflag & PARODD)
621 lpr |= DZ_LPR_OPAR;
622 if (cflag & CSTOPB)
623 lpr |= DZ_LPR_2_STOP;
624
625 DZ_WRITE_WORD(dr_lpr, lpr);
626 DZ_BARRIER();
627
628 (void) splx(s);
629 return (0);
630 }
631
632 static unsigned
633 dzmctl(struct dz_softc *sc, int line, int bits, int how)
634 {
635 unsigned status;
636 unsigned mbits;
637 unsigned bit;
638 int s;
639
640 s = spltty();
641
642 mbits = 0;
643
644 bit = (1 << line);
645
646 /* external signals as seen from the port */
647
648 status = DZ_READ_BYTE(dr_dcd) | sc->sc_dsr;
649
650 if (status & bit)
651 mbits |= DML_DCD;
652
653 status = DZ_READ_BYTE(dr_ring);
654
655 if (status & bit)
656 mbits |= DML_RI;
657
658 /* internal signals/state delivered to port */
659
660 status = DZ_READ_BYTE(dr_dtr);
661
662 if (status & bit)
663 mbits |= DML_DTR;
664
665 if (sc->sc_brk & bit)
666 mbits |= DML_BRK;
667
668 switch (how)
669 {
670 case DMSET:
671 mbits = bits;
672 break;
673
674 case DMBIS:
675 mbits |= bits;
676 break;
677
678 case DMBIC:
679 mbits &= ~bits;
680 break;
681
682 case DMGET:
683 (void) splx(s);
684 return (mbits);
685 }
686
687 if (mbits & DML_DTR) {
688 DZ_WRITE_BYTE(dr_dtr, DZ_READ_BYTE(dr_dtr) | bit);
689 } else {
690 DZ_WRITE_BYTE(dr_dtr, DZ_READ_BYTE(dr_dtr) & ~bit);
691 }
692
693 if (mbits & DML_BRK) {
694 sc->sc_brk |= bit;
695 DZ_WRITE_BYTE(dr_break, sc->sc_brk);
696 } else {
697 sc->sc_brk &= ~bit;
698 DZ_WRITE_BYTE(dr_break, sc->sc_brk);
699 }
700
701 DZ_BARRIER();
702 (void) splx(s);
703 return (mbits);
704 }
705
706 /*
707 * This is called by timeout() periodically.
708 * Check to see if modem status bits have changed.
709 */
710 static void
711 dzscan(void *arg)
712 {
713 struct dz_softc *sc;
714 struct tty *tp;
715 int n, bit, port;
716 unsigned csr;
717 int s;
718
719 s = spltty();
720
721 for (n = 0; n < dz_cd.cd_ndevs; n++) {
722
723 if (dz_cd.cd_devs[n] == NULL)
724 continue;
725
726 sc = dz_cd.cd_devs[n];
727
728 for (port = 0; port < sc->sc_type; port++) {
729
730 tp = sc->sc_dz[port].dz_tty;
731 bit = (1 << port);
732
733 if ((DZ_READ_BYTE(dr_dcd) | sc->sc_dsr) & bit) {
734 if (!(tp->t_state & TS_CARR_ON))
735 (*tp->t_linesw->l_modem) (tp, 1);
736 } else if ((tp->t_state & TS_CARR_ON) &&
737 (*tp->t_linesw->l_modem)(tp, 0) == 0) {
738 DZ_WRITE_BYTE(dr_tcr,
739 (DZ_READ_WORD(dr_tcrw) & 255) & ~bit);
740 DZ_BARRIER();
741 }
742 }
743
744 /*
745 * If the RX interrupt rate is this high, switch
746 * the controller to Silo Alarm - which means don't
747 * interrupt until the RX silo has 16 characters in
748 * it (the silo is 64 characters in all).
749 * Avoid oscillating SA on and off by not turning
750 * if off unless the rate is appropriately low.
751 */
752
753 csr = DZ_READ_WORD(dr_csr);
754
755 if (sc->sc_rxint > (16*10)) {
756 if ((csr & DZ_CSR_SAE) == 0)
757 DZ_WRITE_WORD(dr_csr, csr | DZ_CSR_SAE);
758 } else if ((csr & DZ_CSR_SAE) != 0)
759 if (sc->sc_rxint < 10)
760 DZ_WRITE_WORD(dr_csr, csr & ~(DZ_CSR_SAE));
761
762 DZ_BARRIER();
763 sc->sc_rxint = 0;
764 }
765 (void) splx(s);
766 callout_reset(&dzscan_ch, hz, dzscan, NULL);
767 }
768
769 /*
770 * Called after an ubareset. The DZ card is reset, but the only thing
771 * that must be done is to start the receiver and transmitter again.
772 * No DMA setup to care about.
773 */
774 void
775 dzreset(struct device *dev)
776 {
777 struct dz_softc *sc = (void *)dev;
778 struct tty *tp;
779 int i;
780
781 for (i = 0; i < sc->sc_type; i++) {
782 tp = sc->sc_dz[i].dz_tty;
783
784 if (((tp->t_state & TS_ISOPEN) == 0) || (tp->t_wopen == 0))
785 continue;
786
787 dzparam(tp, &tp->t_termios);
788 dzmctl(sc, i, DML_DTR, DMSET);
789 tp->t_state &= ~TS_BUSY;
790 dzstart(tp); /* Kick off transmitter again */
791 }
792 }
793