Home | History | Annotate | Line # | Download | only in qbus
dhu.c revision 1.33.2.5
      1  1.33.2.5     skrll /*	$NetBSD: dhu.c,v 1.33.2.5 2005/02/04 11:47:09 skrll Exp $	*/
      2       1.1     ragge /*
      3      1.33     ragge  * Copyright (c) 2003, Hugh Graham.
      4       1.1     ragge  * Copyright (c) 1992, 1993
      5       1.1     ragge  *	The Regents of the University of California.  All rights reserved.
      6       1.1     ragge  *
      7       1.1     ragge  * This code is derived from software contributed to Berkeley by
      8       1.1     ragge  * Ralph Campbell and Rick Macklem.
      9       1.1     ragge  *
     10       1.1     ragge  * Redistribution and use in source and binary forms, with or without
     11       1.1     ragge  * modification, are permitted provided that the following conditions
     12       1.1     ragge  * are met:
     13       1.1     ragge  * 1. Redistributions of source code must retain the above copyright
     14       1.1     ragge  *    notice, this list of conditions and the following disclaimer.
     15       1.1     ragge  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1     ragge  *    notice, this list of conditions and the following disclaimer in the
     17       1.1     ragge  *    documentation and/or other materials provided with the distribution.
     18  1.33.2.1     skrll  * 3. Neither the name of the University nor the names of its contributors
     19  1.33.2.1     skrll  *    may be used to endorse or promote products derived from this software
     20  1.33.2.1     skrll  *    without specific prior written permission.
     21  1.33.2.1     skrll  *
     22  1.33.2.1     skrll  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.33.2.1     skrll  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.33.2.1     skrll  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.33.2.1     skrll  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.33.2.1     skrll  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.33.2.1     skrll  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.33.2.1     skrll  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.33.2.1     skrll  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.33.2.1     skrll  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.33.2.1     skrll  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.33.2.1     skrll  * SUCH DAMAGE.
     33  1.33.2.1     skrll  */
     34  1.33.2.1     skrll 
     35  1.33.2.1     skrll /*
     36  1.33.2.1     skrll  * Copyright (c) 1996  Ken C. Wellsch.  All rights reserved.
     37  1.33.2.1     skrll  *
     38  1.33.2.1     skrll  * This code is derived from software contributed to Berkeley by
     39  1.33.2.1     skrll  * Ralph Campbell and Rick Macklem.
     40  1.33.2.1     skrll  *
     41  1.33.2.1     skrll  * Redistribution and use in source and binary forms, with or without
     42  1.33.2.1     skrll  * modification, are permitted provided that the following conditions
     43  1.33.2.1     skrll  * are met:
     44  1.33.2.1     skrll  * 1. Redistributions of source code must retain the above copyright
     45  1.33.2.1     skrll  *    notice, this list of conditions and the following disclaimer.
     46  1.33.2.1     skrll  * 2. Redistributions in binary form must reproduce the above copyright
     47  1.33.2.1     skrll  *    notice, this list of conditions and the following disclaimer in the
     48  1.33.2.1     skrll  *    documentation and/or other materials provided with the distribution.
     49       1.1     ragge  * 3. All advertising materials mentioning features or use of this software
     50       1.1     ragge  *    must display the following acknowledgement:
     51       1.1     ragge  *	This product includes software developed by the University of
     52       1.1     ragge  *	California, Berkeley and its contributors.
     53       1.1     ragge  * 4. Neither the name of the University nor the names of its contributors
     54       1.1     ragge  *    may be used to endorse or promote products derived from this software
     55       1.1     ragge  *    without specific prior written permission.
     56       1.1     ragge  *
     57       1.1     ragge  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     58       1.1     ragge  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     59       1.1     ragge  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     60       1.1     ragge  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     61       1.1     ragge  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     62       1.1     ragge  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     63       1.1     ragge  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     64       1.1     ragge  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     65       1.1     ragge  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     66       1.1     ragge  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     67       1.1     ragge  * SUCH DAMAGE.
     68       1.1     ragge  */
     69      1.25     lukem 
     70      1.25     lukem #include <sys/cdefs.h>
     71  1.33.2.5     skrll __KERNEL_RCSID(0, "$NetBSD: dhu.c,v 1.33.2.5 2005/02/04 11:47:09 skrll Exp $");
     72       1.1     ragge 
     73       1.1     ragge #include <sys/param.h>
     74       1.1     ragge #include <sys/systm.h>
     75       1.1     ragge #include <sys/ioctl.h>
     76       1.1     ragge #include <sys/tty.h>
     77       1.1     ragge #include <sys/proc.h>
     78       1.1     ragge #include <sys/buf.h>
     79       1.1     ragge #include <sys/conf.h>
     80       1.1     ragge #include <sys/file.h>
     81       1.1     ragge #include <sys/uio.h>
     82       1.1     ragge #include <sys/kernel.h>
     83       1.1     ragge #include <sys/syslog.h>
     84       1.1     ragge #include <sys/device.h>
     85       1.1     ragge 
     86      1.15     ragge #include <machine/bus.h>
     87      1.13     ragge #include <machine/scb.h>
     88       1.1     ragge 
     89      1.15     ragge #include <dev/qbus/ubavar.h>
     90      1.15     ragge 
     91      1.15     ragge #include <dev/qbus/dhureg.h>
     92      1.15     ragge 
     93      1.15     ragge #include "ioconf.h"
     94       1.1     ragge 
     95       1.5     ragge /* A DHU-11 has 16 ports while a DHV-11 has only 8. We use 16 by default */
     96       1.1     ragge 
     97       1.5     ragge #define	NDHULINE 	16
     98       1.2     ragge 
     99       1.5     ragge #define DHU_M2U(c)	((c)>>4)	/* convert minor(dev) to unit # */
    100       1.5     ragge #define DHU_LINE(u)	((u)&0xF)	/* extract line # from minor(dev) */
    101       1.2     ragge 
    102       1.5     ragge struct	dhu_softc {
    103       1.5     ragge 	struct	device	sc_dev;		/* Device struct used by config */
    104      1.19      matt 	struct	evcnt	sc_rintrcnt;	/* Interrupt statistics */
    105      1.19      matt 	struct	evcnt	sc_tintrcnt;	/* Interrupt statistics */
    106       1.5     ragge 	int		sc_type;	/* controller type, DHU or DHV */
    107      1.33     ragge 	int		sc_lines;	/* number of lines */
    108      1.15     ragge 	bus_space_tag_t	sc_iot;
    109      1.15     ragge 	bus_space_handle_t sc_ioh;
    110      1.16     ragge 	bus_dma_tag_t	sc_dmat;
    111       1.5     ragge 	struct {
    112       1.5     ragge 		struct	tty *dhu_tty;	/* what we work on */
    113      1.16     ragge 		bus_dmamap_t dhu_dmah;
    114       1.5     ragge 		int	dhu_state;	/* to manage TX output status */
    115       1.5     ragge 		short	dhu_cc;		/* character count on TX */
    116       1.5     ragge 		short	dhu_modem;	/* modem bits state */
    117       1.5     ragge 	} sc_dhu[NDHULINE];
    118       1.1     ragge };
    119       1.1     ragge 
    120       1.5     ragge #define IS_DHU			16	/* Unibus DHU-11 board linecount */
    121       1.5     ragge #define IS_DHV			 8	/* Q-bus DHV-11 or DHQ-11 */
    122       1.2     ragge 
    123       1.2     ragge #define STATE_IDLE		000	/* no current output in progress */
    124       1.2     ragge #define STATE_DMA_RUNNING	001	/* DMA TX in progress */
    125       1.2     ragge #define STATE_DMA_STOPPED	002	/* DMA TX was aborted */
    126       1.2     ragge #define STATE_TX_ONE_CHAR	004	/* did a single char directly */
    127       1.2     ragge 
    128       1.2     ragge /* Flags used to monitor modem bits, make them understood outside driver */
    129       1.2     ragge 
    130       1.2     ragge #define DML_DTR		TIOCM_DTR
    131       1.2     ragge #define DML_RTS		TIOCM_RTS
    132       1.2     ragge #define DML_CTS		TIOCM_CTS
    133       1.2     ragge #define DML_DCD		TIOCM_CD
    134       1.2     ragge #define DML_RI		TIOCM_RI
    135       1.2     ragge #define DML_DSR		TIOCM_DSR
    136       1.2     ragge #define DML_BRK		0100000		/* no equivalent, we will mask */
    137       1.2     ragge 
    138      1.15     ragge #define DHU_READ_WORD(reg) \
    139      1.15     ragge 	bus_space_read_2(sc->sc_iot, sc->sc_ioh, reg)
    140      1.15     ragge #define DHU_WRITE_WORD(reg, val) \
    141      1.15     ragge 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, reg, val)
    142      1.15     ragge #define DHU_READ_BYTE(reg) \
    143      1.15     ragge 	bus_space_read_1(sc->sc_iot, sc->sc_ioh, reg)
    144      1.15     ragge #define DHU_WRITE_BYTE(reg, val) \
    145      1.15     ragge 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, reg, val)
    146      1.15     ragge 
    147      1.15     ragge 
    148       1.1     ragge /*  On a stock DHV, channel pairs (0/1, 2/3, etc.) must use */
    149       1.1     ragge /* a baud rate from the same group.  So limiting to B is likely */
    150       1.1     ragge /* best, although clone boards like the ABLE QHV allow all settings. */
    151       1.1     ragge 
    152  1.33.2.1     skrll static const struct speedtab dhuspeedtab[] = {
    153       1.1     ragge   {       0,	0		},	/* Groups  */
    154       1.1     ragge   {      50,	DHU_LPR_B50	},	/* A	   */
    155       1.1     ragge   {      75,	DHU_LPR_B75	},	/* 	 B */
    156       1.1     ragge   {     110,	DHU_LPR_B110	},	/* A and B */
    157       1.1     ragge   {     134,	DHU_LPR_B134	},	/* A and B */
    158       1.1     ragge   {     150,	DHU_LPR_B150	},	/* 	 B */
    159       1.1     ragge   {     300,	DHU_LPR_B300	},	/* A and B */
    160       1.1     ragge   {     600,	DHU_LPR_B600	},	/* A and B */
    161       1.1     ragge   {    1200,	DHU_LPR_B1200	},	/* A and B */
    162       1.1     ragge   {    1800,	DHU_LPR_B1800	},	/* 	 B */
    163       1.1     ragge   {    2000,	DHU_LPR_B2000	},	/* 	 B */
    164       1.1     ragge   {    2400,	DHU_LPR_B2400	},	/* A and B */
    165       1.1     ragge   {    4800,	DHU_LPR_B4800	},	/* A and B */
    166       1.1     ragge   {    7200,	DHU_LPR_B7200	},	/* A	   */
    167       1.1     ragge   {    9600,	DHU_LPR_B9600	},	/* A and B */
    168       1.1     ragge   {   19200,	DHU_LPR_B19200	},	/* 	 B */
    169       1.1     ragge   {   38400,	DHU_LPR_B38400	},	/* A	   */
    170       1.1     ragge   {      -1,	-1		}
    171       1.1     ragge };
    172       1.1     ragge 
    173  1.33.2.5     skrll static int	dhu_match(struct device *, struct cfdata *, void *);
    174  1.33.2.5     skrll static void	dhu_attach(struct device *, struct device *, void *);
    175  1.33.2.5     skrll static	void	dhurint(void *);
    176  1.33.2.5     skrll static	void	dhuxint(void *);
    177  1.33.2.5     skrll static	void	dhustart(struct tty *);
    178  1.33.2.5     skrll static	int	dhuparam(struct tty *, struct termios *);
    179  1.33.2.5     skrll static	int	dhuiflow(struct tty *, int);
    180  1.33.2.5     skrll static unsigned	dhumctl(struct dhu_softc *,int, int, int);
    181      1.24     ragge 
    182      1.30   thorpej CFATTACH_DECL(dhu, sizeof(struct dhu_softc),
    183      1.31   thorpej     dhu_match, dhu_attach, NULL, NULL);
    184      1.10   thorpej 
    185      1.27   gehenna dev_type_open(dhuopen);
    186      1.27   gehenna dev_type_close(dhuclose);
    187      1.27   gehenna dev_type_read(dhuread);
    188      1.27   gehenna dev_type_write(dhuwrite);
    189      1.27   gehenna dev_type_ioctl(dhuioctl);
    190      1.27   gehenna dev_type_stop(dhustop);
    191      1.27   gehenna dev_type_tty(dhutty);
    192      1.27   gehenna dev_type_poll(dhupoll);
    193      1.27   gehenna 
    194      1.27   gehenna const struct cdevsw dhu_cdevsw = {
    195      1.27   gehenna 	dhuopen, dhuclose, dhuread, dhuwrite, dhuioctl,
    196      1.32  jdolecek 	dhustop, dhutty, dhupoll, nommap, ttykqfilter, D_TTY
    197      1.27   gehenna };
    198      1.27   gehenna 
    199       1.1     ragge /* Autoconfig handles: setup the controller to interrupt, */
    200       1.1     ragge /* then complete the housecleaning for full operation */
    201       1.1     ragge 
    202       1.1     ragge static int
    203      1.11     ragge dhu_match(parent, cf, aux)
    204       1.1     ragge         struct device *parent;
    205      1.11     ragge 	struct cfdata *cf;
    206      1.11     ragge         void *aux;
    207       1.1     ragge {
    208       1.1     ragge 	struct uba_attach_args *ua = aux;
    209      1.18  augustss 	int n;
    210       1.1     ragge 
    211       1.2     ragge 	/* Reset controller to initialize, enable TX/RX interrupts */
    212       1.1     ragge 	/* to catch floating vector info elsewhere when completed */
    213       1.1     ragge 
    214      1.15     ragge 	bus_space_write_2(ua->ua_iot, ua->ua_ioh, DHU_UBA_CSR,
    215      1.15     ragge 	    DHU_CSR_MASTER_RESET | DHU_CSR_RXIE | DHU_CSR_TXIE);
    216       1.1     ragge 
    217       1.1     ragge 	/* Now wait up to 3 seconds for self-test to complete. */
    218       1.1     ragge 
    219       1.1     ragge 	for (n = 0; n < 300; n++) {
    220       1.1     ragge 		DELAY(10000);
    221      1.15     ragge 		if ((bus_space_read_2(ua->ua_iot, ua->ua_ioh, DHU_UBA_CSR) &
    222      1.15     ragge 		    DHU_CSR_MASTER_RESET) == 0)
    223       1.1     ragge 			break;
    224       1.1     ragge 	}
    225       1.1     ragge 
    226       1.1     ragge 	/* If the RESET did not clear after 3 seconds, */
    227       1.1     ragge 	/* the controller must be broken. */
    228       1.1     ragge 
    229       1.2     ragge 	if (n >= 300)
    230       1.1     ragge 		return 0;
    231       1.1     ragge 
    232       1.1     ragge 	/* Check whether diagnostic run has signalled a failure. */
    233       1.1     ragge 
    234      1.15     ragge 	if ((bus_space_read_2(ua->ua_iot, ua->ua_ioh, DHU_UBA_CSR) &
    235      1.15     ragge 	    DHU_CSR_DIAG_FAIL) != 0)
    236       1.1     ragge 		return 0;
    237       1.1     ragge 
    238       1.1     ragge        	return 1;
    239       1.1     ragge }
    240       1.1     ragge 
    241       1.1     ragge static void
    242       1.5     ragge dhu_attach(parent, self, aux)
    243       1.1     ragge         struct device *parent, *self;
    244       1.1     ragge         void *aux;
    245       1.1     ragge {
    246      1.18  augustss 	struct dhu_softc *sc = (void *)self;
    247      1.18  augustss 	struct uba_attach_args *ua = aux;
    248      1.18  augustss 	unsigned c;
    249      1.18  augustss 	int n, i;
    250       1.1     ragge 
    251      1.15     ragge 	sc->sc_iot = ua->ua_iot;
    252      1.15     ragge 	sc->sc_ioh = ua->ua_ioh;
    253      1.16     ragge 	sc->sc_dmat = ua->ua_dmat;
    254       1.1     ragge 	/* Process the 8 bytes of diagnostic info put into */
    255       1.1     ragge 	/* the FIFO following the master reset operation. */
    256       1.1     ragge 
    257       1.8  christos 	printf("\n%s:", self->dv_xname);
    258       1.1     ragge 	for (n = 0; n < 8; n++) {
    259      1.15     ragge 		c = DHU_READ_WORD(DHU_UBA_RBUF);
    260       1.1     ragge 
    261       1.2     ragge 		if ((c&DHU_DIAG_CODE) == DHU_DIAG_CODE) {
    262       1.2     ragge 			if ((c&0200) == 0000)
    263       1.8  christos 				printf(" rom(%d) version %d",
    264       1.1     ragge 					((c>>1)&01), ((c>>2)&037));
    265       1.2     ragge 			else if (((c>>2)&07) != 0)
    266       1.8  christos 				printf(" diag-error(proc%d)=%x",
    267       1.1     ragge 					((c>>1)&01), ((c>>2)&07));
    268       1.1     ragge 		}
    269       1.1     ragge 	}
    270       1.1     ragge 
    271      1.15     ragge 	c = DHU_READ_WORD(DHU_UBA_STAT);
    272       1.2     ragge 
    273       1.5     ragge 	sc->sc_type = (c & DHU_STAT_DHU)? IS_DHU: IS_DHV;
    274       1.1     ragge 
    275      1.33     ragge 	sc->sc_lines = 8;	/* default */
    276      1.33     ragge 	if (sc->sc_type == IS_DHU && (c & DHU_STAT_MDL))
    277      1.33     ragge 		sc->sc_lines = 16;
    278      1.33     ragge 
    279      1.33     ragge 	printf("\n%s: DH%s-11\n", self->dv_xname,
    280      1.33     ragge 	    sc->sc_type == IS_DHU ? "U" : "V");
    281      1.33     ragge 
    282      1.33     ragge 	for (i = 0; i < sc->sc_lines; i++) {
    283      1.16     ragge 		struct tty *tp;
    284      1.16     ragge 		tp = sc->sc_dhu[i].dhu_tty = ttymalloc();
    285      1.16     ragge 		sc->sc_dhu[i].dhu_state = STATE_IDLE;
    286      1.16     ragge 		bus_dmamap_create(sc->sc_dmat, tp->t_outq.c_cn, 1,
    287      1.16     ragge 		    tp->t_outq.c_cn, 0, BUS_DMA_ALLOCNOW|BUS_DMA_NOWAIT,
    288      1.16     ragge 		    &sc->sc_dhu[i].dhu_dmah);
    289      1.16     ragge 		bus_dmamap_load(sc->sc_dmat, sc->sc_dhu[i].dhu_dmah,
    290      1.16     ragge 		    tp->t_outq.c_cs, tp->t_outq.c_cn, 0, BUS_DMA_NOWAIT);
    291      1.16     ragge 
    292      1.16     ragge 	}
    293      1.16     ragge 
    294      1.17      matt 	/* Now establish RX & TX interrupt handlers */
    295      1.17      matt 
    296      1.19      matt 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec,
    297      1.19      matt 		dhurint, sc, &sc->sc_rintrcnt);
    298      1.19      matt 	uba_intr_establish(ua->ua_icookie, ua->ua_cvec + 4,
    299      1.19      matt 		dhuxint, sc, &sc->sc_tintrcnt);
    300      1.20      matt 	evcnt_attach_dynamic(&sc->sc_rintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
    301      1.20      matt 		sc->sc_dev.dv_xname, "rintr");
    302      1.20      matt 	evcnt_attach_dynamic(&sc->sc_tintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
    303      1.20      matt 		sc->sc_dev.dv_xname, "tintr");
    304       1.1     ragge }
    305       1.1     ragge 
    306       1.2     ragge /* Receiver Interrupt */
    307       1.2     ragge 
    308       1.1     ragge static void
    309      1.17      matt dhurint(arg)
    310      1.17      matt 	void *arg;
    311       1.1     ragge {
    312      1.17      matt 	struct	dhu_softc *sc = arg;
    313      1.18  augustss 	struct tty *tp;
    314      1.18  augustss 	int cc, line;
    315      1.18  augustss 	unsigned c, delta;
    316       1.1     ragge 	int overrun = 0;
    317       1.2     ragge 
    318      1.15     ragge 	while ((c = DHU_READ_WORD(DHU_UBA_RBUF)) & DHU_RBUF_DATA_VALID) {
    319       1.1     ragge 
    320       1.1     ragge 		/* Ignore diagnostic FIFO entries. */
    321       1.1     ragge 
    322       1.5     ragge 		if ((c & DHU_DIAG_CODE) == DHU_DIAG_CODE)
    323       1.1     ragge 			continue;
    324       1.1     ragge 
    325       1.5     ragge 		cc = c & 0xFF;
    326       1.5     ragge 		line = DHU_LINE(c>>8);
    327       1.5     ragge 		tp = sc->sc_dhu[line].dhu_tty;
    328       1.1     ragge 
    329       1.1     ragge 		/* LINK.TYPE is set so we get modem control FIFO entries */
    330       1.1     ragge 
    331       1.1     ragge 		if ((c & DHU_DIAG_CODE) == DHU_MODEM_CODE) {
    332       1.2     ragge 			c = (c << 8);
    333       1.1     ragge 			/* Do MDMBUF flow control, wakeup sleeping opens */
    334       1.1     ragge 			if (c & DHU_STAT_DCD) {
    335       1.1     ragge 				if (!(tp->t_state & TS_CARR_ON))
    336      1.21       eeh 				    (void)(*tp->t_linesw->l_modem)(tp, 1);
    337       1.1     ragge 			}
    338       1.1     ragge 			else if ((tp->t_state & TS_CARR_ON) &&
    339      1.21       eeh 				(*tp->t_linesw->l_modem)(tp, 0) == 0)
    340       1.5     ragge 					(void) dhumctl(sc, line, 0, DMSET);
    341       1.2     ragge 
    342       1.2     ragge 			/* Do CRTSCTS flow control */
    343       1.5     ragge 			delta = c ^ sc->sc_dhu[line].dhu_modem;
    344       1.5     ragge 			sc->sc_dhu[line].dhu_modem = c;
    345       1.2     ragge 			if ((delta & DHU_STAT_CTS) &&
    346       1.2     ragge 			    (tp->t_state & TS_ISOPEN) &&
    347       1.2     ragge 			    (tp->t_cflag & CRTSCTS)) {
    348       1.2     ragge 				if (c & DHU_STAT_CTS) {
    349       1.2     ragge 					tp->t_state &= ~TS_TTSTOP;
    350       1.5     ragge 					ttstart(tp);
    351       1.2     ragge 				} else {
    352       1.2     ragge 					tp->t_state |= TS_TTSTOP;
    353       1.5     ragge 					dhustop(tp, 0);
    354       1.2     ragge 				}
    355       1.2     ragge 			}
    356       1.2     ragge 			continue;
    357       1.1     ragge 		}
    358       1.1     ragge 
    359       1.5     ragge 		if (!(tp->t_state & TS_ISOPEN)) {
    360       1.5     ragge 			wakeup((caddr_t)&tp->t_rawq);
    361       1.5     ragge 			continue;
    362       1.5     ragge 		}
    363       1.5     ragge 
    364       1.1     ragge 		if ((c & DHU_RBUF_OVERRUN_ERR) && overrun == 0) {
    365       1.5     ragge 			log(LOG_WARNING, "%s: silo overflow, line %d\n",
    366       1.5     ragge 				sc->sc_dev.dv_xname, line);
    367       1.1     ragge 			overrun = 1;
    368       1.1     ragge 		}
    369       1.1     ragge 		/* A BREAK key will appear as a NULL with a framing error */
    370       1.1     ragge 		if (c & DHU_RBUF_FRAMING_ERR)
    371       1.1     ragge 			cc |= TTY_FE;
    372       1.1     ragge 		if (c & DHU_RBUF_PARITY_ERR)
    373       1.1     ragge 			cc |= TTY_PE;
    374       1.1     ragge 
    375      1.21       eeh 		(*tp->t_linesw->l_rint)(cc, tp);
    376       1.1     ragge 	}
    377       1.1     ragge }
    378       1.1     ragge 
    379       1.1     ragge /* Transmitter Interrupt */
    380       1.1     ragge 
    381       1.1     ragge static void
    382      1.17      matt dhuxint(arg)
    383      1.17      matt 	void *arg;
    384       1.1     ragge {
    385      1.18  augustss 	struct	dhu_softc *sc = arg;
    386      1.18  augustss 	struct tty *tp;
    387      1.33     ragge 	int line, i;
    388       1.2     ragge 
    389      1.33     ragge 	while ((i = DHU_READ_BYTE(DHU_UBA_CSR_HI)) & (DHU_CSR_TX_ACTION >> 8)) {
    390       1.1     ragge 
    391      1.33     ragge 		line = DHU_LINE(i);
    392      1.33     ragge 		tp = sc->sc_dhu[line].dhu_tty;
    393       1.2     ragge 
    394      1.33     ragge 		if (i & (DHU_CSR_TX_DMA_ERROR >> 8))
    395      1.33     ragge 			printf("%s: DMA ERROR on line: %d\n",
    396      1.33     ragge 			    sc->sc_dev.dv_xname, line);
    397      1.33     ragge 		if (i & (DHU_CSR_DIAG_FAIL >> 8))
    398      1.33     ragge 			printf("%s: DIAG FAIL on line: %d\n",
    399      1.33     ragge 			    sc->sc_dev.dv_xname, line);
    400      1.33     ragge 
    401      1.33     ragge 		tp->t_state &= ~TS_BUSY;
    402      1.33     ragge 		if (tp->t_state & TS_FLUSH)
    403      1.33     ragge 			tp->t_state &= ~TS_FLUSH;
    404      1.33     ragge 		else {
    405      1.33     ragge 			if (sc->sc_dhu[line].dhu_state == STATE_DMA_STOPPED)
    406      1.33     ragge 				sc->sc_dhu[line].dhu_cc -=
    407      1.33     ragge 				    DHU_READ_WORD(DHU_UBA_TBUFCNT);
    408      1.33     ragge 			ndflush(&tp->t_outq, sc->sc_dhu[line].dhu_cc);
    409      1.33     ragge 			sc->sc_dhu[line].dhu_cc = 0;
    410      1.33     ragge 		}
    411       1.1     ragge 
    412      1.33     ragge 		sc->sc_dhu[line].dhu_state = STATE_IDLE;
    413       1.2     ragge 
    414      1.33     ragge 		(*tp->t_linesw->l_start)(tp);
    415      1.33     ragge 	}
    416       1.1     ragge }
    417       1.1     ragge 
    418       1.1     ragge int
    419  1.33.2.4     skrll dhuopen(dev, flag, mode, l)
    420       1.1     ragge 	dev_t dev;
    421       1.1     ragge 	int flag, mode;
    422  1.33.2.4     skrll 	struct lwp *l;
    423       1.1     ragge {
    424      1.18  augustss 	struct tty *tp;
    425      1.18  augustss 	int unit, line;
    426       1.5     ragge 	struct dhu_softc *sc;
    427       1.1     ragge 	int s, error = 0;
    428       1.1     ragge 
    429       1.5     ragge 	unit = DHU_M2U(minor(dev));
    430       1.5     ragge 	line = DHU_LINE(minor(dev));
    431       1.5     ragge 
    432       1.5     ragge 	if (unit >= dhu_cd.cd_ndevs || dhu_cd.cd_devs[unit] == NULL)
    433       1.1     ragge 		return (ENXIO);
    434       1.5     ragge 
    435       1.5     ragge 	sc = dhu_cd.cd_devs[unit];
    436       1.5     ragge 
    437      1.33     ragge 	if (line >= sc->sc_lines)
    438       1.5     ragge 		return ENXIO;
    439       1.5     ragge 
    440      1.33     ragge 	if (sc->sc_type == IS_DHU) {
    441      1.33     ragge 		s = spltty();	/* CSR 3:0 must be 0 */
    442      1.33     ragge 		DHU_WRITE_BYTE(DHU_UBA_CSR, DHU_CSR_RXIE);
    443      1.33     ragge 		DHU_WRITE_BYTE(DHU_UBA_RXTIME, 10);
    444      1.33     ragge 		splx(s);	/* RX int delay 10ms */
    445      1.33     ragge 	}
    446      1.33     ragge 
    447      1.16     ragge 	s = spltty();
    448      1.16     ragge 	DHU_WRITE_BYTE(DHU_UBA_CSR, DHU_CSR_RXIE | line);
    449      1.16     ragge 	sc->sc_dhu[line].dhu_modem = DHU_READ_WORD(DHU_UBA_STAT);
    450      1.16     ragge 	(void) splx(s);
    451      1.16     ragge 
    452       1.5     ragge 	tp = sc->sc_dhu[line].dhu_tty;
    453       1.5     ragge 
    454       1.2     ragge 	tp->t_oproc   = dhustart;
    455       1.2     ragge 	tp->t_param   = dhuparam;
    456       1.2     ragge 	tp->t_hwiflow = dhuiflow;
    457       1.1     ragge 	tp->t_dev = dev;
    458       1.1     ragge 	if ((tp->t_state & TS_ISOPEN) == 0) {
    459       1.1     ragge 		ttychars(tp);
    460       1.2     ragge 		if (tp->t_ispeed == 0) {
    461       1.2     ragge 			tp->t_iflag = TTYDEF_IFLAG;
    462       1.2     ragge 			tp->t_oflag = TTYDEF_OFLAG;
    463       1.2     ragge 			tp->t_cflag = TTYDEF_CFLAG;
    464       1.2     ragge 			tp->t_lflag = TTYDEF_LFLAG;
    465       1.2     ragge 			tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
    466       1.2     ragge 		}
    467       1.1     ragge 		(void) dhuparam(tp, &tp->t_termios);
    468       1.1     ragge 		ttsetwater(tp);
    469       1.1     ragge 	} else if ((tp->t_state & TS_XCLUDE) && curproc->p_ucred->cr_uid != 0)
    470       1.1     ragge 		return (EBUSY);
    471       1.1     ragge 	/* Use DMBIS and *not* DMSET or else we clobber incoming bits */
    472       1.5     ragge 	if (dhumctl(sc, line, DML_DTR|DML_RTS, DMBIS) & DML_DCD)
    473       1.1     ragge 		tp->t_state |= TS_CARR_ON;
    474       1.1     ragge 	s = spltty();
    475       1.1     ragge 	while (!(flag & O_NONBLOCK) && !(tp->t_cflag & CLOCAL) &&
    476       1.1     ragge 	       !(tp->t_state & TS_CARR_ON)) {
    477      1.12     ragge 		tp->t_wopen++;
    478       1.1     ragge 		error = ttysleep(tp, (caddr_t)&tp->t_rawq,
    479       1.1     ragge 				TTIPRI | PCATCH, ttopen, 0);
    480      1.12     ragge 		tp->t_wopen--;
    481       1.1     ragge 		if (error)
    482       1.1     ragge 			break;
    483       1.1     ragge 	}
    484       1.1     ragge 	(void) splx(s);
    485       1.1     ragge 	if (error)
    486       1.1     ragge 		return (error);
    487      1.21       eeh 	return ((*tp->t_linesw->l_open)(dev, tp));
    488       1.1     ragge }
    489       1.1     ragge 
    490       1.1     ragge /*ARGSUSED*/
    491       1.1     ragge int
    492  1.33.2.4     skrll dhuclose(dev, flag, mode, l)
    493       1.1     ragge 	dev_t dev;
    494       1.1     ragge 	int flag, mode;
    495  1.33.2.4     skrll 	struct lwp *l;
    496       1.1     ragge {
    497      1.18  augustss 	struct tty *tp;
    498      1.18  augustss 	int unit, line;
    499       1.5     ragge 	struct dhu_softc *sc;
    500       1.5     ragge 
    501       1.5     ragge 	unit = DHU_M2U(minor(dev));
    502       1.5     ragge 	line = DHU_LINE(minor(dev));
    503       1.1     ragge 
    504       1.5     ragge 	sc = dhu_cd.cd_devs[unit];
    505       1.5     ragge 
    506       1.5     ragge 	tp = sc->sc_dhu[line].dhu_tty;
    507       1.1     ragge 
    508      1.21       eeh 	(*tp->t_linesw->l_close)(tp, flag);
    509       1.1     ragge 
    510       1.1     ragge 	/* Make sure a BREAK state is not left enabled. */
    511       1.1     ragge 
    512       1.5     ragge 	(void) dhumctl(sc, line, DML_BRK, DMBIC);
    513       1.1     ragge 
    514       1.1     ragge 	/* Do a hangup if so required. */
    515       1.1     ragge 
    516      1.12     ragge 	if ((tp->t_cflag & HUPCL) || tp->t_wopen ||
    517       1.1     ragge 	    !(tp->t_state & TS_ISOPEN))
    518       1.5     ragge 		(void) dhumctl(sc, line, 0, DMSET);
    519       1.1     ragge 
    520       1.1     ragge 	return (ttyclose(tp));
    521       1.1     ragge }
    522       1.1     ragge 
    523       1.1     ragge int
    524       1.5     ragge dhuread(dev, uio, flag)
    525       1.1     ragge 	dev_t dev;
    526       1.1     ragge 	struct uio *uio;
    527      1.27   gehenna 	int flag;
    528       1.1     ragge {
    529      1.18  augustss 	struct dhu_softc *sc;
    530      1.18  augustss 	struct tty *tp;
    531       1.1     ragge 
    532       1.5     ragge 	sc = dhu_cd.cd_devs[DHU_M2U(minor(dev))];
    533       1.5     ragge 
    534       1.5     ragge 	tp = sc->sc_dhu[DHU_LINE(minor(dev))].dhu_tty;
    535      1.21       eeh 	return ((*tp->t_linesw->l_read)(tp, uio, flag));
    536       1.1     ragge }
    537       1.1     ragge 
    538       1.1     ragge int
    539       1.5     ragge dhuwrite(dev, uio, flag)
    540       1.1     ragge 	dev_t dev;
    541       1.1     ragge 	struct uio *uio;
    542      1.27   gehenna 	int flag;
    543       1.1     ragge {
    544      1.18  augustss 	struct dhu_softc *sc;
    545      1.18  augustss 	struct tty *tp;
    546       1.1     ragge 
    547       1.5     ragge 	sc = dhu_cd.cd_devs[DHU_M2U(minor(dev))];
    548       1.5     ragge 
    549       1.5     ragge 	tp = sc->sc_dhu[DHU_LINE(minor(dev))].dhu_tty;
    550      1.21       eeh 	return ((*tp->t_linesw->l_write)(tp, uio, flag));
    551      1.23       scw }
    552      1.23       scw 
    553      1.23       scw int
    554  1.33.2.4     skrll dhupoll(dev, events, l)
    555      1.23       scw 	dev_t dev;
    556      1.23       scw 	int events;
    557  1.33.2.4     skrll 	struct lwp *l;
    558      1.23       scw {
    559      1.23       scw 	struct dhu_softc *sc;
    560      1.23       scw 	struct tty *tp;
    561      1.23       scw 
    562      1.23       scw 	sc = dhu_cd.cd_devs[DHU_M2U(minor(dev))];
    563      1.23       scw 
    564      1.23       scw 	tp = sc->sc_dhu[DHU_LINE(minor(dev))].dhu_tty;
    565  1.33.2.4     skrll 	return ((*tp->t_linesw->l_poll)(tp, events, l));
    566       1.1     ragge }
    567       1.1     ragge 
    568       1.1     ragge /*ARGSUSED*/
    569       1.1     ragge int
    570  1.33.2.4     skrll dhuioctl(dev, cmd, data, flag, l)
    571       1.1     ragge 	dev_t dev;
    572       1.4     ragge 	u_long cmd;
    573       1.1     ragge 	caddr_t data;
    574       1.1     ragge 	int flag;
    575  1.33.2.4     skrll 	struct lwp *l;
    576       1.1     ragge {
    577      1.18  augustss 	struct dhu_softc *sc;
    578      1.18  augustss 	struct tty *tp;
    579      1.18  augustss 	int unit, line;
    580       1.1     ragge 	int error;
    581       1.1     ragge 
    582       1.5     ragge 	unit = DHU_M2U(minor(dev));
    583       1.5     ragge 	line = DHU_LINE(minor(dev));
    584       1.5     ragge 	sc = dhu_cd.cd_devs[unit];
    585       1.5     ragge 	tp = sc->sc_dhu[line].dhu_tty;
    586       1.5     ragge 
    587  1.33.2.4     skrll 	error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, l);
    588      1.26    atatat 	if (error != EPASSTHROUGH)
    589       1.1     ragge 		return (error);
    590      1.26    atatat 
    591  1.33.2.4     skrll 	error = ttioctl(tp, cmd, data, flag, l);
    592      1.26    atatat 	if (error != EPASSTHROUGH)
    593       1.1     ragge 		return (error);
    594       1.1     ragge 
    595       1.1     ragge 	switch (cmd) {
    596       1.1     ragge 
    597       1.1     ragge 	case TIOCSBRK:
    598       1.5     ragge 		(void) dhumctl(sc, line, DML_BRK, DMBIS);
    599       1.1     ragge 		break;
    600       1.1     ragge 
    601       1.1     ragge 	case TIOCCBRK:
    602       1.5     ragge 		(void) dhumctl(sc, line, DML_BRK, DMBIC);
    603       1.1     ragge 		break;
    604       1.1     ragge 
    605       1.1     ragge 	case TIOCSDTR:
    606       1.5     ragge 		(void) dhumctl(sc, line, DML_DTR|DML_RTS, DMBIS);
    607       1.1     ragge 		break;
    608       1.1     ragge 
    609       1.1     ragge 	case TIOCCDTR:
    610       1.5     ragge 		(void) dhumctl(sc, line, DML_DTR|DML_RTS, DMBIC);
    611       1.1     ragge 		break;
    612       1.1     ragge 
    613       1.1     ragge 	case TIOCMSET:
    614       1.5     ragge 		(void) dhumctl(sc, line, *(int *)data, DMSET);
    615       1.1     ragge 		break;
    616       1.1     ragge 
    617       1.1     ragge 	case TIOCMBIS:
    618       1.5     ragge 		(void) dhumctl(sc, line, *(int *)data, DMBIS);
    619       1.1     ragge 		break;
    620       1.1     ragge 
    621       1.1     ragge 	case TIOCMBIC:
    622       1.5     ragge 		(void) dhumctl(sc, line, *(int *)data, DMBIC);
    623       1.1     ragge 		break;
    624       1.1     ragge 
    625       1.1     ragge 	case TIOCMGET:
    626       1.5     ragge 		*(int *)data = (dhumctl(sc, line, 0, DMGET) & ~DML_BRK);
    627       1.1     ragge 		break;
    628       1.1     ragge 
    629       1.1     ragge 	default:
    630      1.26    atatat 		return (EPASSTHROUGH);
    631       1.1     ragge 	}
    632       1.1     ragge 	return (0);
    633       1.1     ragge }
    634       1.1     ragge 
    635       1.2     ragge struct tty *
    636       1.5     ragge dhutty(dev)
    637       1.2     ragge         dev_t dev;
    638       1.2     ragge {
    639       1.5     ragge 	struct dhu_softc *sc = dhu_cd.cd_devs[DHU_M2U(minor(dev))];
    640       1.5     ragge 	struct tty *tp = sc->sc_dhu[DHU_LINE(minor(dev))].dhu_tty;
    641       1.2     ragge         return (tp);
    642       1.2     ragge }
    643       1.2     ragge 
    644       1.1     ragge /*ARGSUSED*/
    645       1.6   mycroft void
    646       1.5     ragge dhustop(tp, flag)
    647      1.18  augustss 	struct tty *tp;
    648      1.27   gehenna 	int flag;
    649       1.1     ragge {
    650      1.18  augustss 	struct dhu_softc *sc;
    651      1.18  augustss 	int line;
    652       1.1     ragge 	int s;
    653       1.1     ragge 
    654       1.1     ragge 	s = spltty();
    655       1.1     ragge 
    656       1.5     ragge 	if (tp->t_state & TS_BUSY) {
    657       1.5     ragge 
    658       1.5     ragge 		sc = dhu_cd.cd_devs[DHU_M2U(minor(tp->t_dev))];
    659       1.5     ragge 		line = DHU_LINE(minor(tp->t_dev));
    660       1.5     ragge 
    661       1.5     ragge 		if (sc->sc_dhu[line].dhu_state == STATE_DMA_RUNNING) {
    662       1.5     ragge 
    663       1.5     ragge 			sc->sc_dhu[line].dhu_state = STATE_DMA_STOPPED;
    664       1.2     ragge 
    665      1.15     ragge 			DHU_WRITE_BYTE(DHU_UBA_CSR, DHU_CSR_RXIE | line);
    666      1.15     ragge 			DHU_WRITE_WORD(DHU_UBA_LNCTRL,
    667      1.15     ragge 			    DHU_READ_WORD(DHU_UBA_LNCTRL) |
    668      1.15     ragge 			    DHU_LNCTRL_DMA_ABORT);
    669       1.2     ragge 		}
    670       1.1     ragge 
    671       1.1     ragge 		if (!(tp->t_state & TS_TTSTOP))
    672       1.1     ragge 			tp->t_state |= TS_FLUSH;
    673       1.1     ragge 	}
    674       1.1     ragge 	(void) splx(s);
    675       1.1     ragge }
    676       1.1     ragge 
    677       1.1     ragge static void
    678       1.5     ragge dhustart(tp)
    679      1.18  augustss 	struct tty *tp;
    680       1.1     ragge {
    681      1.18  augustss 	struct dhu_softc *sc;
    682      1.18  augustss 	int line, cc;
    683      1.18  augustss 	int addr;
    684       1.1     ragge 	int s;
    685       1.1     ragge 
    686       1.1     ragge 	s = spltty();
    687       1.1     ragge 	if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
    688       1.1     ragge 		goto out;
    689       1.1     ragge 	if (tp->t_outq.c_cc <= tp->t_lowat) {
    690       1.1     ragge 		if (tp->t_state & TS_ASLEEP) {
    691       1.1     ragge 			tp->t_state &= ~TS_ASLEEP;
    692       1.1     ragge 			wakeup((caddr_t)&tp->t_outq);
    693       1.1     ragge 		}
    694       1.1     ragge 		selwakeup(&tp->t_wsel);
    695       1.1     ragge 	}
    696       1.1     ragge 	if (tp->t_outq.c_cc == 0)
    697       1.1     ragge 		goto out;
    698       1.1     ragge 	cc = ndqb(&tp->t_outq, 0);
    699       1.1     ragge 	if (cc == 0)
    700       1.1     ragge 		goto out;
    701       1.1     ragge 
    702       1.1     ragge 	tp->t_state |= TS_BUSY;
    703       1.1     ragge 
    704       1.5     ragge 	sc = dhu_cd.cd_devs[DHU_M2U(minor(tp->t_dev))];
    705       1.5     ragge 
    706       1.5     ragge 	line = DHU_LINE(minor(tp->t_dev));
    707       1.1     ragge 
    708      1.15     ragge 	DHU_WRITE_BYTE(DHU_UBA_CSR, DHU_CSR_RXIE | line);
    709       1.5     ragge 
    710       1.5     ragge 	sc->sc_dhu[line].dhu_cc = cc;
    711       1.2     ragge 
    712      1.33     ragge 	if (cc == 1 && sc->sc_type == IS_DHV) {
    713       1.2     ragge 
    714       1.5     ragge 		sc->sc_dhu[line].dhu_state = STATE_TX_ONE_CHAR;
    715      1.15     ragge 
    716      1.15     ragge 		DHU_WRITE_WORD(DHU_UBA_TXCHAR,
    717      1.15     ragge 		    DHU_TXCHAR_DATA_VALID | *tp->t_outq.c_cf);
    718       1.2     ragge 
    719       1.5     ragge 	} else {
    720       1.5     ragge 
    721       1.5     ragge 		sc->sc_dhu[line].dhu_state = STATE_DMA_RUNNING;
    722       1.5     ragge 
    723      1.16     ragge 		addr = sc->sc_dhu[line].dhu_dmah->dm_segs[0].ds_addr +
    724       1.2     ragge 			(tp->t_outq.c_cf - tp->t_outq.c_cs);
    725       1.2     ragge 
    726      1.15     ragge 		DHU_WRITE_WORD(DHU_UBA_TBUFCNT, cc);
    727      1.15     ragge 		DHU_WRITE_WORD(DHU_UBA_TBUFAD1, addr & 0xFFFF);
    728      1.15     ragge 		DHU_WRITE_WORD(DHU_UBA_TBUFAD2, ((addr>>16) & 0x3F) |
    729      1.15     ragge 		    DHU_TBUFAD2_TX_ENABLE);
    730      1.15     ragge 		DHU_WRITE_WORD(DHU_UBA_LNCTRL,
    731      1.15     ragge 		    DHU_READ_WORD(DHU_UBA_LNCTRL) & ~DHU_LNCTRL_DMA_ABORT);
    732      1.15     ragge 		DHU_WRITE_WORD(DHU_UBA_TBUFAD2,
    733      1.15     ragge 		    DHU_READ_WORD(DHU_UBA_TBUFAD2) | DHU_TBUFAD2_DMA_START);
    734       1.2     ragge 	}
    735       1.1     ragge out:
    736       1.1     ragge 	(void) splx(s);
    737       1.1     ragge 	return;
    738       1.1     ragge }
    739       1.1     ragge 
    740       1.1     ragge static int
    741       1.5     ragge dhuparam(tp, t)
    742      1.18  augustss 	struct tty *tp;
    743      1.18  augustss 	struct termios *t;
    744       1.1     ragge {
    745       1.5     ragge 	struct dhu_softc *sc;
    746      1.18  augustss 	int cflag = t->c_cflag;
    747       1.1     ragge 	int ispeed = ttspeedtab(t->c_ispeed, dhuspeedtab);
    748       1.1     ragge 	int ospeed = ttspeedtab(t->c_ospeed, dhuspeedtab);
    749      1.18  augustss 	unsigned lpr, lnctrl;
    750       1.5     ragge 	int unit, line;
    751       1.1     ragge 	int s;
    752       1.1     ragge 
    753       1.5     ragge 	unit = DHU_M2U(minor(tp->t_dev));
    754       1.5     ragge 	line = DHU_LINE(minor(tp->t_dev));
    755       1.5     ragge 
    756       1.5     ragge 	sc = dhu_cd.cd_devs[unit];
    757       1.5     ragge 
    758       1.1     ragge 	/* check requested parameters */
    759       1.1     ragge         if (ospeed < 0 || ispeed < 0)
    760       1.1     ragge                 return (EINVAL);
    761       1.1     ragge 
    762       1.1     ragge         tp->t_ispeed = t->c_ispeed;
    763       1.1     ragge         tp->t_ospeed = t->c_ospeed;
    764       1.1     ragge         tp->t_cflag = cflag;
    765       1.1     ragge 
    766       1.1     ragge 	if (ospeed == 0) {
    767       1.5     ragge 		(void) dhumctl(sc, line, 0, DMSET);	/* hang up line */
    768       1.1     ragge 		return (0);
    769       1.1     ragge 	}
    770       1.1     ragge 
    771       1.1     ragge 	s = spltty();
    772      1.15     ragge 	DHU_WRITE_BYTE(DHU_UBA_CSR, DHU_CSR_RXIE | line);
    773       1.1     ragge 
    774       1.1     ragge 	lpr = ((ispeed&017)<<8) | ((ospeed&017)<<12) ;
    775       1.1     ragge 
    776       1.5     ragge 	switch (cflag & CSIZE) {
    777       1.5     ragge 
    778       1.5     ragge 	case CS5:
    779       1.1     ragge 		lpr |= DHU_LPR_5_BIT_CHAR;
    780       1.1     ragge 		break;
    781       1.5     ragge 
    782       1.5     ragge 	case CS6:
    783       1.1     ragge 		lpr |= DHU_LPR_6_BIT_CHAR;
    784       1.1     ragge 		break;
    785       1.5     ragge 
    786       1.5     ragge 	case CS7:
    787       1.1     ragge 		lpr |= DHU_LPR_7_BIT_CHAR;
    788       1.1     ragge 		break;
    789       1.5     ragge 
    790       1.5     ragge 	default:
    791       1.1     ragge 		lpr |= DHU_LPR_8_BIT_CHAR;
    792       1.1     ragge 		break;
    793       1.1     ragge 	}
    794       1.5     ragge 
    795       1.1     ragge 	if (cflag & PARENB)
    796       1.1     ragge 		lpr |= DHU_LPR_PARENB;
    797       1.1     ragge 	if (!(cflag & PARODD))
    798       1.1     ragge 		lpr |= DHU_LPR_EPAR;
    799       1.1     ragge 	if (cflag & CSTOPB)
    800       1.1     ragge 		lpr |= DHU_LPR_2_STOP;
    801       1.1     ragge 
    802      1.15     ragge 	DHU_WRITE_WORD(DHU_UBA_LPR, lpr);
    803       1.1     ragge 
    804      1.15     ragge 	DHU_WRITE_WORD(DHU_UBA_TBUFAD2,
    805      1.15     ragge 	    DHU_READ_WORD(DHU_UBA_TBUFAD2) | DHU_TBUFAD2_TX_ENABLE);
    806       1.2     ragge 
    807      1.15     ragge 	lnctrl = DHU_READ_WORD(DHU_UBA_LNCTRL);
    808       1.2     ragge 
    809       1.1     ragge 	/* Setting LINK.TYPE enables modem signal change interrupts. */
    810       1.1     ragge 
    811       1.2     ragge 	lnctrl |= (DHU_LNCTRL_RX_ENABLE | DHU_LNCTRL_LINK_TYPE);
    812       1.2     ragge 
    813       1.5     ragge 	/* Enable the auto XON/XOFF feature on the controller */
    814       1.5     ragge 
    815       1.2     ragge 	if (t->c_iflag & IXON)
    816       1.2     ragge 		lnctrl |= DHU_LNCTRL_OAUTO;
    817       1.2     ragge 	else
    818       1.2     ragge 		lnctrl &= ~DHU_LNCTRL_OAUTO;
    819       1.2     ragge 
    820       1.2     ragge 	if (t->c_iflag & IXOFF)
    821       1.2     ragge 		lnctrl |= DHU_LNCTRL_IAUTO;
    822       1.2     ragge 	else
    823       1.2     ragge 		lnctrl &= ~DHU_LNCTRL_IAUTO;
    824       1.2     ragge 
    825      1.15     ragge 	DHU_WRITE_WORD(DHU_UBA_LNCTRL, lnctrl);
    826       1.2     ragge 
    827       1.1     ragge 	(void) splx(s);
    828       1.1     ragge 	return (0);
    829       1.1     ragge }
    830       1.1     ragge 
    831       1.1     ragge static int
    832       1.5     ragge dhuiflow(tp, flag)
    833       1.2     ragge 	struct tty *tp;
    834       1.2     ragge 	int flag;
    835       1.2     ragge {
    836      1.18  augustss 	struct dhu_softc *sc;
    837      1.18  augustss 	int line = DHU_LINE(minor(tp->t_dev));
    838       1.2     ragge 
    839       1.2     ragge 	if (tp->t_cflag & CRTSCTS) {
    840       1.5     ragge 		sc = dhu_cd.cd_devs[DHU_M2U(minor(tp->t_dev))];
    841       1.5     ragge 		(void) dhumctl(sc, line, DML_RTS, ((flag)? DMBIC: DMBIS));
    842       1.2     ragge 		return (1);
    843       1.2     ragge 	}
    844       1.2     ragge 	return (0);
    845       1.2     ragge }
    846       1.2     ragge 
    847       1.2     ragge static unsigned
    848       1.5     ragge dhumctl(sc, line, bits, how)
    849       1.5     ragge 	struct dhu_softc *sc;
    850       1.5     ragge 	int line, bits, how;
    851       1.1     ragge {
    852      1.18  augustss 	unsigned status;
    853      1.18  augustss 	unsigned lnctrl;
    854      1.18  augustss 	unsigned mbits;
    855       1.1     ragge 	int s;
    856       1.1     ragge 
    857       1.1     ragge 	s = spltty();
    858       1.1     ragge 
    859      1.15     ragge 	DHU_WRITE_BYTE(DHU_UBA_CSR, DHU_CSR_RXIE | line);
    860       1.1     ragge 
    861       1.1     ragge 	mbits = 0;
    862       1.1     ragge 
    863       1.1     ragge 	/* external signals as seen from the port */
    864       1.1     ragge 
    865      1.15     ragge 	status = DHU_READ_WORD(DHU_UBA_STAT);
    866       1.1     ragge 
    867       1.2     ragge 	if (status & DHU_STAT_CTS)
    868       1.1     ragge 		mbits |= DML_CTS;
    869       1.1     ragge 
    870       1.2     ragge 	if (status & DHU_STAT_DCD)
    871       1.1     ragge 		mbits |= DML_DCD;
    872       1.1     ragge 
    873       1.2     ragge 	if (status & DHU_STAT_DSR)
    874       1.1     ragge 		mbits |= DML_DSR;
    875       1.1     ragge 
    876       1.2     ragge 	if (status & DHU_STAT_RI)
    877       1.1     ragge 		mbits |= DML_RI;
    878       1.1     ragge 
    879       1.1     ragge 	/* internal signals/state delivered to port */
    880       1.1     ragge 
    881      1.15     ragge 	lnctrl = DHU_READ_WORD(DHU_UBA_LNCTRL);
    882       1.1     ragge 
    883       1.2     ragge 	if (lnctrl & DHU_LNCTRL_RTS)
    884       1.1     ragge 		mbits |= DML_RTS;
    885       1.1     ragge 
    886       1.2     ragge 	if (lnctrl & DHU_LNCTRL_DTR)
    887       1.1     ragge 		mbits |= DML_DTR;
    888       1.1     ragge 
    889       1.2     ragge 	if (lnctrl & DHU_LNCTRL_BREAK)
    890       1.1     ragge 		mbits |= DML_BRK;
    891       1.1     ragge 
    892       1.5     ragge 	switch (how) {
    893       1.5     ragge 
    894       1.5     ragge 	case DMSET:
    895       1.1     ragge 		mbits = bits;
    896       1.1     ragge 		break;
    897       1.1     ragge 
    898       1.5     ragge 	case DMBIS:
    899       1.1     ragge 		mbits |= bits;
    900       1.1     ragge 		break;
    901       1.1     ragge 
    902       1.5     ragge 	case DMBIC:
    903       1.1     ragge 		mbits &= ~bits;
    904       1.1     ragge 		break;
    905       1.1     ragge 
    906       1.5     ragge 	case DMGET:
    907       1.1     ragge 		(void) splx(s);
    908       1.1     ragge 		return (mbits);
    909       1.1     ragge 	}
    910       1.1     ragge 
    911       1.1     ragge 	if (mbits & DML_RTS)
    912       1.2     ragge 		lnctrl |= DHU_LNCTRL_RTS;
    913       1.1     ragge 	else
    914       1.2     ragge 		lnctrl &= ~DHU_LNCTRL_RTS;
    915       1.1     ragge 
    916       1.1     ragge 	if (mbits & DML_DTR)
    917       1.2     ragge 		lnctrl |= DHU_LNCTRL_DTR;
    918       1.1     ragge 	else
    919       1.2     ragge 		lnctrl &= ~DHU_LNCTRL_DTR;
    920       1.1     ragge 
    921       1.1     ragge 	if (mbits & DML_BRK)
    922       1.2     ragge 		lnctrl |= DHU_LNCTRL_BREAK;
    923       1.1     ragge 	else
    924       1.2     ragge 		lnctrl &= ~DHU_LNCTRL_BREAK;
    925       1.2     ragge 
    926      1.15     ragge 	DHU_WRITE_WORD(DHU_UBA_LNCTRL, lnctrl);
    927       1.1     ragge 
    928       1.1     ragge 	(void) splx(s);
    929       1.1     ragge 	return (mbits);
    930       1.1     ragge }
    931