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