dhu.c revision 1.17 1 /* $NetBSD: dhu.c,v 1.17 2000/01/24 02:40:28 matt 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/param.h>
40 #include <sys/systm.h>
41 #include <sys/ioctl.h>
42 #include <sys/tty.h>
43 #include <sys/proc.h>
44 #include <sys/map.h>
45 #include <sys/buf.h>
46 #include <sys/conf.h>
47 #include <sys/file.h>
48 #include <sys/uio.h>
49 #include <sys/kernel.h>
50 #include <sys/syslog.h>
51 #include <sys/device.h>
52
53 #include <machine/bus.h>
54 #include <machine/scb.h>
55
56 #include <dev/qbus/ubavar.h>
57
58 #include <dev/qbus/dhureg.h>
59
60 #include "ioconf.h"
61
62 /* A DHU-11 has 16 ports while a DHV-11 has only 8. We use 16 by default */
63
64 #define NDHULINE 16
65
66 #define DHU_M2U(c) ((c)>>4) /* convert minor(dev) to unit # */
67 #define DHU_LINE(u) ((u)&0xF) /* extract line # from minor(dev) */
68
69 struct dhu_softc {
70 struct device sc_dev; /* Device struct used by config */
71 int sc_type; /* controller type, DHU or DHV */
72 bus_space_tag_t sc_iot;
73 bus_space_handle_t sc_ioh;
74 bus_dma_tag_t sc_dmat;
75 struct {
76 struct tty *dhu_tty; /* what we work on */
77 bus_dmamap_t dhu_dmah;
78 int dhu_state; /* to manage TX output status */
79 short dhu_cc; /* character count on TX */
80 short dhu_modem; /* modem bits state */
81 } sc_dhu[NDHULINE];
82 };
83
84 #define IS_DHU 16 /* Unibus DHU-11 board linecount */
85 #define IS_DHV 8 /* Q-bus DHV-11 or DHQ-11 */
86
87 #define STATE_IDLE 000 /* no current output in progress */
88 #define STATE_DMA_RUNNING 001 /* DMA TX in progress */
89 #define STATE_DMA_STOPPED 002 /* DMA TX was aborted */
90 #define STATE_TX_ONE_CHAR 004 /* did a single char directly */
91
92 /* Flags used to monitor modem bits, make them understood outside driver */
93
94 #define DML_DTR TIOCM_DTR
95 #define DML_RTS TIOCM_RTS
96 #define DML_CTS TIOCM_CTS
97 #define DML_DCD TIOCM_CD
98 #define DML_RI TIOCM_RI
99 #define DML_DSR TIOCM_DSR
100 #define DML_BRK 0100000 /* no equivalent, we will mask */
101
102 #define DHU_READ_WORD(reg) \
103 bus_space_read_2(sc->sc_iot, sc->sc_ioh, reg)
104 #define DHU_WRITE_WORD(reg, val) \
105 bus_space_write_2(sc->sc_iot, sc->sc_ioh, reg, val)
106 #define DHU_READ_BYTE(reg) \
107 bus_space_read_1(sc->sc_iot, sc->sc_ioh, reg)
108 #define DHU_WRITE_BYTE(reg, val) \
109 bus_space_write_1(sc->sc_iot, sc->sc_ioh, reg, val)
110
111
112 /* On a stock DHV, channel pairs (0/1, 2/3, etc.) must use */
113 /* a baud rate from the same group. So limiting to B is likely */
114 /* best, although clone boards like the ABLE QHV allow all settings. */
115
116 static struct speedtab dhuspeedtab[] = {
117 { 0, 0 }, /* Groups */
118 { 50, DHU_LPR_B50 }, /* A */
119 { 75, DHU_LPR_B75 }, /* B */
120 { 110, DHU_LPR_B110 }, /* A and B */
121 { 134, DHU_LPR_B134 }, /* A and B */
122 { 150, DHU_LPR_B150 }, /* B */
123 { 300, DHU_LPR_B300 }, /* A and B */
124 { 600, DHU_LPR_B600 }, /* A and B */
125 { 1200, DHU_LPR_B1200 }, /* A and B */
126 { 1800, DHU_LPR_B1800 }, /* B */
127 { 2000, DHU_LPR_B2000 }, /* B */
128 { 2400, DHU_LPR_B2400 }, /* A and B */
129 { 4800, DHU_LPR_B4800 }, /* A and B */
130 { 7200, DHU_LPR_B7200 }, /* A */
131 { 9600, DHU_LPR_B9600 }, /* A and B */
132 { 19200, DHU_LPR_B19200 }, /* B */
133 { 38400, DHU_LPR_B38400 }, /* A */
134 { -1, -1 }
135 };
136
137 static int dhu_match __P((struct device *, struct cfdata *, void *));
138 static void dhu_attach __P((struct device *, struct device *, void *));
139 static void dhurint __P((void *));
140 static void dhuxint __P((void *));
141 static void dhustart __P((struct tty *));
142 static int dhuparam __P((struct tty *, struct termios *));
143 static int dhuiflow __P((struct tty *, int));
144 static unsigned dhumctl __P((struct dhu_softc *,int, int, int));
145 int dhuopen __P((dev_t, int, int, struct proc *));
146 int dhuclose __P((dev_t, int, int, struct proc *));
147 int dhuread __P((dev_t, struct uio *, int));
148 int dhuwrite __P((dev_t, struct uio *, int));
149 int dhuioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
150 void dhustop __P((struct tty *, int));
151 struct tty * dhutty __P((dev_t));
152
153 struct cfattach dhu_ca = {
154 sizeof(struct dhu_softc), dhu_match, dhu_attach
155 };
156
157 /* Autoconfig handles: setup the controller to interrupt, */
158 /* then complete the housecleaning for full operation */
159
160 static int
161 dhu_match(parent, cf, aux)
162 struct device *parent;
163 struct cfdata *cf;
164 void *aux;
165 {
166 struct uba_attach_args *ua = aux;
167 register int n;
168
169 /* Reset controller to initialize, enable TX/RX interrupts */
170 /* to catch floating vector info elsewhere when completed */
171
172 bus_space_write_2(ua->ua_iot, ua->ua_ioh, DHU_UBA_CSR,
173 DHU_CSR_MASTER_RESET | DHU_CSR_RXIE | DHU_CSR_TXIE);
174
175 /* Now wait up to 3 seconds for self-test to complete. */
176
177 for (n = 0; n < 300; n++) {
178 DELAY(10000);
179 if ((bus_space_read_2(ua->ua_iot, ua->ua_ioh, DHU_UBA_CSR) &
180 DHU_CSR_MASTER_RESET) == 0)
181 break;
182 }
183
184 /* If the RESET did not clear after 3 seconds, */
185 /* the controller must be broken. */
186
187 if (n >= 300)
188 return 0;
189
190 /* Check whether diagnostic run has signalled a failure. */
191
192 if ((bus_space_read_2(ua->ua_iot, ua->ua_ioh, DHU_UBA_CSR) &
193 DHU_CSR_DIAG_FAIL) != 0)
194 return 0;
195
196 return 1;
197 }
198
199 static void
200 dhu_attach(parent, self, aux)
201 struct device *parent, *self;
202 void *aux;
203 {
204 register struct dhu_softc *sc = (void *)self;
205 register struct uba_attach_args *ua = aux;
206 register unsigned c;
207 register int n, i;
208
209 sc->sc_iot = ua->ua_iot;
210 sc->sc_ioh = ua->ua_ioh;
211 sc->sc_dmat = ua->ua_dmat;
212 /* Process the 8 bytes of diagnostic info put into */
213 /* the FIFO following the master reset operation. */
214
215 printf("\n%s:", self->dv_xname);
216 for (n = 0; n < 8; n++) {
217 c = DHU_READ_WORD(DHU_UBA_RBUF);
218
219 if ((c&DHU_DIAG_CODE) == DHU_DIAG_CODE) {
220 if ((c&0200) == 0000)
221 printf(" rom(%d) version %d",
222 ((c>>1)&01), ((c>>2)&037));
223 else if (((c>>2)&07) != 0)
224 printf(" diag-error(proc%d)=%x",
225 ((c>>1)&01), ((c>>2)&07));
226 }
227 }
228
229 c = DHU_READ_WORD(DHU_UBA_STAT);
230
231 sc->sc_type = (c & DHU_STAT_DHU)? IS_DHU: IS_DHV;
232 printf("\n%s: DH%s-11\n", self->dv_xname, (c & DHU_STAT_DHU)?"U":"V");
233
234 for (i = 0; i < sc->sc_type; i++) {
235 struct tty *tp;
236 tp = sc->sc_dhu[i].dhu_tty = ttymalloc();
237 sc->sc_dhu[i].dhu_state = STATE_IDLE;
238 bus_dmamap_create(sc->sc_dmat, tp->t_outq.c_cn, 1,
239 tp->t_outq.c_cn, 0, BUS_DMA_ALLOCNOW|BUS_DMA_NOWAIT,
240 &sc->sc_dhu[i].dhu_dmah);
241 bus_dmamap_load(sc->sc_dmat, sc->sc_dhu[i].dhu_dmah,
242 tp->t_outq.c_cs, tp->t_outq.c_cn, 0, BUS_DMA_NOWAIT);
243
244 }
245
246 /* Now establish RX & TX interrupt handlers */
247
248 uba_intr_establish(ua->ua_icookie, ua->ua_cvec , dhurint, sc);
249 uba_intr_establish(ua->ua_icookie, ua->ua_cvec + 4, dhuxint, sc);
250 }
251
252 /* Receiver Interrupt */
253
254 static void
255 dhurint(arg)
256 void *arg;
257 {
258 struct dhu_softc *sc = arg;
259 register struct tty *tp;
260 register int cc, line;
261 register unsigned c, delta;
262 int overrun = 0;
263
264 while ((c = DHU_READ_WORD(DHU_UBA_RBUF)) & DHU_RBUF_DATA_VALID) {
265
266 /* Ignore diagnostic FIFO entries. */
267
268 if ((c & DHU_DIAG_CODE) == DHU_DIAG_CODE)
269 continue;
270
271 cc = c & 0xFF;
272 line = DHU_LINE(c>>8);
273 tp = sc->sc_dhu[line].dhu_tty;
274
275 /* LINK.TYPE is set so we get modem control FIFO entries */
276
277 if ((c & DHU_DIAG_CODE) == DHU_MODEM_CODE) {
278 c = (c << 8);
279 /* Do MDMBUF flow control, wakeup sleeping opens */
280 if (c & DHU_STAT_DCD) {
281 if (!(tp->t_state & TS_CARR_ON))
282 (void)(*linesw[tp->t_line].l_modem)(tp, 1);
283 }
284 else if ((tp->t_state & TS_CARR_ON) &&
285 (*linesw[tp->t_line].l_modem)(tp, 0) == 0)
286 (void) dhumctl(sc, line, 0, DMSET);
287
288 /* Do CRTSCTS flow control */
289 delta = c ^ sc->sc_dhu[line].dhu_modem;
290 sc->sc_dhu[line].dhu_modem = c;
291 if ((delta & DHU_STAT_CTS) &&
292 (tp->t_state & TS_ISOPEN) &&
293 (tp->t_cflag & CRTSCTS)) {
294 if (c & DHU_STAT_CTS) {
295 tp->t_state &= ~TS_TTSTOP;
296 ttstart(tp);
297 } else {
298 tp->t_state |= TS_TTSTOP;
299 dhustop(tp, 0);
300 }
301 }
302 continue;
303 }
304
305 if (!(tp->t_state & TS_ISOPEN)) {
306 wakeup((caddr_t)&tp->t_rawq);
307 continue;
308 }
309
310 if ((c & DHU_RBUF_OVERRUN_ERR) && overrun == 0) {
311 log(LOG_WARNING, "%s: silo overflow, line %d\n",
312 sc->sc_dev.dv_xname, line);
313 overrun = 1;
314 }
315 /* A BREAK key will appear as a NULL with a framing error */
316 if (c & DHU_RBUF_FRAMING_ERR)
317 cc |= TTY_FE;
318 if (c & DHU_RBUF_PARITY_ERR)
319 cc |= TTY_PE;
320
321 (*linesw[tp->t_line].l_rint)(cc, tp);
322 }
323 }
324
325 /* Transmitter Interrupt */
326
327 static void
328 dhuxint(arg)
329 void *arg;
330 {
331 register struct dhu_softc *sc = arg;
332 register struct tty *tp;
333 register int line;
334
335 line = DHU_LINE(DHU_READ_BYTE(DHU_UBA_CSR_HI));
336
337 tp = sc->sc_dhu[line].dhu_tty;
338
339 tp->t_state &= ~TS_BUSY;
340 if (tp->t_state & TS_FLUSH)
341 tp->t_state &= ~TS_FLUSH;
342 else {
343 if (sc->sc_dhu[line].dhu_state == STATE_DMA_STOPPED)
344 sc->sc_dhu[line].dhu_cc -=
345 DHU_READ_WORD(DHU_UBA_TBUFCNT);
346 ndflush(&tp->t_outq, sc->sc_dhu[line].dhu_cc);
347 sc->sc_dhu[line].dhu_cc = 0;
348 }
349
350 sc->sc_dhu[line].dhu_state = STATE_IDLE;
351
352 if (tp->t_line)
353 (*linesw[tp->t_line].l_start)(tp);
354 else
355 dhustart(tp);
356 }
357
358 int
359 dhuopen(dev, flag, mode, p)
360 dev_t dev;
361 int flag, mode;
362 struct proc *p;
363 {
364 register struct tty *tp;
365 register int unit, line;
366 struct dhu_softc *sc;
367 int s, error = 0;
368
369 unit = DHU_M2U(minor(dev));
370 line = DHU_LINE(minor(dev));
371
372 if (unit >= dhu_cd.cd_ndevs || dhu_cd.cd_devs[unit] == NULL)
373 return (ENXIO);
374
375 sc = dhu_cd.cd_devs[unit];
376
377 if (line >= sc->sc_type)
378 return ENXIO;
379
380 s = spltty();
381 DHU_WRITE_BYTE(DHU_UBA_CSR, DHU_CSR_RXIE | line);
382 sc->sc_dhu[line].dhu_modem = DHU_READ_WORD(DHU_UBA_STAT);
383 (void) splx(s);
384
385 tp = sc->sc_dhu[line].dhu_tty;
386
387 tp->t_oproc = dhustart;
388 tp->t_param = dhuparam;
389 tp->t_hwiflow = dhuiflow;
390 tp->t_dev = dev;
391 if ((tp->t_state & TS_ISOPEN) == 0) {
392 ttychars(tp);
393 if (tp->t_ispeed == 0) {
394 tp->t_iflag = TTYDEF_IFLAG;
395 tp->t_oflag = TTYDEF_OFLAG;
396 tp->t_cflag = TTYDEF_CFLAG;
397 tp->t_lflag = TTYDEF_LFLAG;
398 tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
399 }
400 (void) dhuparam(tp, &tp->t_termios);
401 ttsetwater(tp);
402 } else if ((tp->t_state & TS_XCLUDE) && curproc->p_ucred->cr_uid != 0)
403 return (EBUSY);
404 /* Use DMBIS and *not* DMSET or else we clobber incoming bits */
405 if (dhumctl(sc, line, DML_DTR|DML_RTS, DMBIS) & DML_DCD)
406 tp->t_state |= TS_CARR_ON;
407 s = spltty();
408 while (!(flag & O_NONBLOCK) && !(tp->t_cflag & CLOCAL) &&
409 !(tp->t_state & TS_CARR_ON)) {
410 tp->t_wopen++;
411 error = ttysleep(tp, (caddr_t)&tp->t_rawq,
412 TTIPRI | PCATCH, ttopen, 0);
413 tp->t_wopen--;
414 if (error)
415 break;
416 }
417 (void) splx(s);
418 if (error)
419 return (error);
420 return ((*linesw[tp->t_line].l_open)(dev, tp));
421 }
422
423 /*ARGSUSED*/
424 int
425 dhuclose(dev, flag, mode, p)
426 dev_t dev;
427 int flag, mode;
428 struct proc *p;
429 {
430 register struct tty *tp;
431 register int unit, line;
432 struct dhu_softc *sc;
433
434 unit = DHU_M2U(minor(dev));
435 line = DHU_LINE(minor(dev));
436
437 sc = dhu_cd.cd_devs[unit];
438
439 tp = sc->sc_dhu[line].dhu_tty;
440
441 (*linesw[tp->t_line].l_close)(tp, flag);
442
443 /* Make sure a BREAK state is not left enabled. */
444
445 (void) dhumctl(sc, line, DML_BRK, DMBIC);
446
447 /* Do a hangup if so required. */
448
449 if ((tp->t_cflag & HUPCL) || tp->t_wopen ||
450 !(tp->t_state & TS_ISOPEN))
451 (void) dhumctl(sc, line, 0, DMSET);
452
453 return (ttyclose(tp));
454 }
455
456 int
457 dhuread(dev, uio, flag)
458 dev_t dev;
459 struct uio *uio;
460 {
461 register struct dhu_softc *sc;
462 register struct tty *tp;
463
464 sc = dhu_cd.cd_devs[DHU_M2U(minor(dev))];
465
466 tp = sc->sc_dhu[DHU_LINE(minor(dev))].dhu_tty;
467 return ((*linesw[tp->t_line].l_read)(tp, uio, flag));
468 }
469
470 int
471 dhuwrite(dev, uio, flag)
472 dev_t dev;
473 struct uio *uio;
474 {
475 register struct dhu_softc *sc;
476 register struct tty *tp;
477
478 sc = dhu_cd.cd_devs[DHU_M2U(minor(dev))];
479
480 tp = sc->sc_dhu[DHU_LINE(minor(dev))].dhu_tty;
481 return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
482 }
483
484 /*ARGSUSED*/
485 int
486 dhuioctl(dev, cmd, data, flag, p)
487 dev_t dev;
488 u_long cmd;
489 caddr_t data;
490 int flag;
491 struct proc *p;
492 {
493 register struct dhu_softc *sc;
494 register struct tty *tp;
495 register int unit, line;
496 int error;
497
498 unit = DHU_M2U(minor(dev));
499 line = DHU_LINE(minor(dev));
500 sc = dhu_cd.cd_devs[unit];
501 tp = sc->sc_dhu[line].dhu_tty;
502
503 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
504 if (error >= 0)
505 return (error);
506 error = ttioctl(tp, cmd, data, flag, p);
507 if (error >= 0)
508 return (error);
509
510 switch (cmd) {
511
512 case TIOCSBRK:
513 (void) dhumctl(sc, line, DML_BRK, DMBIS);
514 break;
515
516 case TIOCCBRK:
517 (void) dhumctl(sc, line, DML_BRK, DMBIC);
518 break;
519
520 case TIOCSDTR:
521 (void) dhumctl(sc, line, DML_DTR|DML_RTS, DMBIS);
522 break;
523
524 case TIOCCDTR:
525 (void) dhumctl(sc, line, DML_DTR|DML_RTS, DMBIC);
526 break;
527
528 case TIOCMSET:
529 (void) dhumctl(sc, line, *(int *)data, DMSET);
530 break;
531
532 case TIOCMBIS:
533 (void) dhumctl(sc, line, *(int *)data, DMBIS);
534 break;
535
536 case TIOCMBIC:
537 (void) dhumctl(sc, line, *(int *)data, DMBIC);
538 break;
539
540 case TIOCMGET:
541 *(int *)data = (dhumctl(sc, line, 0, DMGET) & ~DML_BRK);
542 break;
543
544 default:
545 return (ENOTTY);
546 }
547 return (0);
548 }
549
550 struct tty *
551 dhutty(dev)
552 dev_t dev;
553 {
554 struct dhu_softc *sc = dhu_cd.cd_devs[DHU_M2U(minor(dev))];
555 struct tty *tp = sc->sc_dhu[DHU_LINE(minor(dev))].dhu_tty;
556 return (tp);
557 }
558
559 /*ARGSUSED*/
560 void
561 dhustop(tp, flag)
562 register struct tty *tp;
563 {
564 register struct dhu_softc *sc;
565 register int line;
566 int s;
567
568 s = spltty();
569
570 if (tp->t_state & TS_BUSY) {
571
572 sc = dhu_cd.cd_devs[DHU_M2U(minor(tp->t_dev))];
573 line = DHU_LINE(minor(tp->t_dev));
574
575 if (sc->sc_dhu[line].dhu_state == STATE_DMA_RUNNING) {
576
577 sc->sc_dhu[line].dhu_state = STATE_DMA_STOPPED;
578
579 DHU_WRITE_BYTE(DHU_UBA_CSR, DHU_CSR_RXIE | line);
580 DHU_WRITE_WORD(DHU_UBA_LNCTRL,
581 DHU_READ_WORD(DHU_UBA_LNCTRL) |
582 DHU_LNCTRL_DMA_ABORT);
583 }
584
585 if (!(tp->t_state & TS_TTSTOP))
586 tp->t_state |= TS_FLUSH;
587 }
588 (void) splx(s);
589 }
590
591 static void
592 dhustart(tp)
593 register struct tty *tp;
594 {
595 register struct dhu_softc *sc;
596 register int line, cc;
597 register int addr;
598 int s;
599
600 s = spltty();
601 if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
602 goto out;
603 if (tp->t_outq.c_cc <= tp->t_lowat) {
604 if (tp->t_state & TS_ASLEEP) {
605 tp->t_state &= ~TS_ASLEEP;
606 wakeup((caddr_t)&tp->t_outq);
607 }
608 selwakeup(&tp->t_wsel);
609 }
610 if (tp->t_outq.c_cc == 0)
611 goto out;
612 cc = ndqb(&tp->t_outq, 0);
613 if (cc == 0)
614 goto out;
615
616 tp->t_state |= TS_BUSY;
617
618 sc = dhu_cd.cd_devs[DHU_M2U(minor(tp->t_dev))];
619
620 line = DHU_LINE(minor(tp->t_dev));
621
622 DHU_WRITE_BYTE(DHU_UBA_CSR, DHU_CSR_RXIE | line);
623
624 sc->sc_dhu[line].dhu_cc = cc;
625
626 if (cc == 1) {
627
628 sc->sc_dhu[line].dhu_state = STATE_TX_ONE_CHAR;
629
630 DHU_WRITE_WORD(DHU_UBA_TXCHAR,
631 DHU_TXCHAR_DATA_VALID | *tp->t_outq.c_cf);
632
633 } else {
634
635 sc->sc_dhu[line].dhu_state = STATE_DMA_RUNNING;
636
637 addr = sc->sc_dhu[line].dhu_dmah->dm_segs[0].ds_addr +
638 (tp->t_outq.c_cf - tp->t_outq.c_cs);
639
640 DHU_WRITE_WORD(DHU_UBA_TBUFCNT, cc);
641 DHU_WRITE_WORD(DHU_UBA_TBUFAD1, addr & 0xFFFF);
642 DHU_WRITE_WORD(DHU_UBA_TBUFAD2, ((addr>>16) & 0x3F) |
643 DHU_TBUFAD2_TX_ENABLE);
644 DHU_WRITE_WORD(DHU_UBA_LNCTRL,
645 DHU_READ_WORD(DHU_UBA_LNCTRL) & ~DHU_LNCTRL_DMA_ABORT);
646 DHU_WRITE_WORD(DHU_UBA_TBUFAD2,
647 DHU_READ_WORD(DHU_UBA_TBUFAD2) | DHU_TBUFAD2_DMA_START);
648 }
649 out:
650 (void) splx(s);
651 return;
652 }
653
654 static int
655 dhuparam(tp, t)
656 register struct tty *tp;
657 register struct termios *t;
658 {
659 struct dhu_softc *sc;
660 register int cflag = t->c_cflag;
661 int ispeed = ttspeedtab(t->c_ispeed, dhuspeedtab);
662 int ospeed = ttspeedtab(t->c_ospeed, dhuspeedtab);
663 register unsigned lpr, lnctrl;
664 int unit, line;
665 int s;
666
667 unit = DHU_M2U(minor(tp->t_dev));
668 line = DHU_LINE(minor(tp->t_dev));
669
670 sc = dhu_cd.cd_devs[unit];
671
672 /* check requested parameters */
673 if (ospeed < 0 || ispeed < 0)
674 return (EINVAL);
675
676 tp->t_ispeed = t->c_ispeed;
677 tp->t_ospeed = t->c_ospeed;
678 tp->t_cflag = cflag;
679
680 if (ospeed == 0) {
681 (void) dhumctl(sc, line, 0, DMSET); /* hang up line */
682 return (0);
683 }
684
685 s = spltty();
686 DHU_WRITE_BYTE(DHU_UBA_CSR, DHU_CSR_RXIE | line);
687
688 lpr = ((ispeed&017)<<8) | ((ospeed&017)<<12) ;
689
690 switch (cflag & CSIZE) {
691
692 case CS5:
693 lpr |= DHU_LPR_5_BIT_CHAR;
694 break;
695
696 case CS6:
697 lpr |= DHU_LPR_6_BIT_CHAR;
698 break;
699
700 case CS7:
701 lpr |= DHU_LPR_7_BIT_CHAR;
702 break;
703
704 default:
705 lpr |= DHU_LPR_8_BIT_CHAR;
706 break;
707 }
708
709 if (cflag & PARENB)
710 lpr |= DHU_LPR_PARENB;
711 if (!(cflag & PARODD))
712 lpr |= DHU_LPR_EPAR;
713 if (cflag & CSTOPB)
714 lpr |= DHU_LPR_2_STOP;
715
716 DHU_WRITE_WORD(DHU_UBA_LPR, lpr);
717
718 DHU_WRITE_WORD(DHU_UBA_TBUFAD2,
719 DHU_READ_WORD(DHU_UBA_TBUFAD2) | DHU_TBUFAD2_TX_ENABLE);
720
721 lnctrl = DHU_READ_WORD(DHU_UBA_LNCTRL);
722
723 /* Setting LINK.TYPE enables modem signal change interrupts. */
724
725 lnctrl |= (DHU_LNCTRL_RX_ENABLE | DHU_LNCTRL_LINK_TYPE);
726
727 /* Enable the auto XON/XOFF feature on the controller */
728
729 if (t->c_iflag & IXON)
730 lnctrl |= DHU_LNCTRL_OAUTO;
731 else
732 lnctrl &= ~DHU_LNCTRL_OAUTO;
733
734 if (t->c_iflag & IXOFF)
735 lnctrl |= DHU_LNCTRL_IAUTO;
736 else
737 lnctrl &= ~DHU_LNCTRL_IAUTO;
738
739 DHU_WRITE_WORD(DHU_UBA_LNCTRL, lnctrl);
740
741 (void) splx(s);
742 return (0);
743 }
744
745 static int
746 dhuiflow(tp, flag)
747 struct tty *tp;
748 int flag;
749 {
750 register struct dhu_softc *sc;
751 register int line = DHU_LINE(minor(tp->t_dev));
752
753 if (tp->t_cflag & CRTSCTS) {
754 sc = dhu_cd.cd_devs[DHU_M2U(minor(tp->t_dev))];
755 (void) dhumctl(sc, line, DML_RTS, ((flag)? DMBIC: DMBIS));
756 return (1);
757 }
758 return (0);
759 }
760
761 static unsigned
762 dhumctl(sc, line, bits, how)
763 struct dhu_softc *sc;
764 int line, bits, how;
765 {
766 register unsigned status;
767 register unsigned lnctrl;
768 register unsigned mbits;
769 int s;
770
771 s = spltty();
772
773 DHU_WRITE_BYTE(DHU_UBA_CSR, DHU_CSR_RXIE | line);
774
775 mbits = 0;
776
777 /* external signals as seen from the port */
778
779 status = DHU_READ_WORD(DHU_UBA_STAT);
780
781 if (status & DHU_STAT_CTS)
782 mbits |= DML_CTS;
783
784 if (status & DHU_STAT_DCD)
785 mbits |= DML_DCD;
786
787 if (status & DHU_STAT_DSR)
788 mbits |= DML_DSR;
789
790 if (status & DHU_STAT_RI)
791 mbits |= DML_RI;
792
793 /* internal signals/state delivered to port */
794
795 lnctrl = DHU_READ_WORD(DHU_UBA_LNCTRL);
796
797 if (lnctrl & DHU_LNCTRL_RTS)
798 mbits |= DML_RTS;
799
800 if (lnctrl & DHU_LNCTRL_DTR)
801 mbits |= DML_DTR;
802
803 if (lnctrl & DHU_LNCTRL_BREAK)
804 mbits |= DML_BRK;
805
806 switch (how) {
807
808 case DMSET:
809 mbits = bits;
810 break;
811
812 case DMBIS:
813 mbits |= bits;
814 break;
815
816 case DMBIC:
817 mbits &= ~bits;
818 break;
819
820 case DMGET:
821 (void) splx(s);
822 return (mbits);
823 }
824
825 if (mbits & DML_RTS)
826 lnctrl |= DHU_LNCTRL_RTS;
827 else
828 lnctrl &= ~DHU_LNCTRL_RTS;
829
830 if (mbits & DML_DTR)
831 lnctrl |= DHU_LNCTRL_DTR;
832 else
833 lnctrl &= ~DHU_LNCTRL_DTR;
834
835 if (mbits & DML_BRK)
836 lnctrl |= DHU_LNCTRL_BREAK;
837 else
838 lnctrl &= ~DHU_LNCTRL_BREAK;
839
840 DHU_WRITE_WORD(DHU_UBA_LNCTRL, lnctrl);
841
842 (void) splx(s);
843 return (mbits);
844 }
845