Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/qbus Copied from ../../arch/vax/uba/dhu.c,v
details: https://anonhg.NetBSD.org/src/rev/d78c1e422c33
branches: trunk
changeset: 473302:d78c1e422c33
user: ragge <ragge%NetBSD.org@localhost>
date: Fri May 28 18:56:41 1999 +0000
description:
Copied from ../../arch/vax/uba/dhu.c,v
diffstat:
sys/dev/qbus/dhu.c | 847 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 847 insertions(+), 0 deletions(-)
diffs (truncated from 851 to 300 lines):
diff -r a9953a6cd800 -r d78c1e422c33 sys/dev/qbus/dhu.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/qbus/dhu.c Fri May 28 18:56:41 1999 +0000
@@ -0,0 +1,847 @@
+/* $NetBSD: dhu.c,v 1.14 1999/05/28 18:56:41 ragge Exp $ */
+/*
+ * Copyright (c) 1996 Ken C. Wellsch. All rights reserved.
+ * Copyright (c) 1992, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Ralph Campbell and Rick Macklem.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/ioctl.h>
+#include <sys/tty.h>
+#include <sys/proc.h>
+#include <sys/map.h>
+#include <sys/buf.h>
+#include <sys/conf.h>
+#include <sys/file.h>
+#include <sys/uio.h>
+#include <sys/kernel.h>
+#include <sys/syslog.h>
+#include <sys/device.h>
+
+#include <machine/trap.h>
+#include <machine/scb.h>
+
+#include <vax/uba/ubavar.h>
+#include <vax/uba/dhureg.h>
+
+/* A DHU-11 has 16 ports while a DHV-11 has only 8. We use 16 by default */
+
+#define NDHULINE 16
+
+#define DHU_M2U(c) ((c)>>4) /* convert minor(dev) to unit # */
+#define DHU_LINE(u) ((u)&0xF) /* extract line # from minor(dev) */
+
+struct dhu_softc {
+ struct device sc_dev; /* Device struct used by config */
+ dhuregs * sc_addr; /* controller reg address */
+ int sc_type; /* controller type, DHU or DHV */
+ struct {
+ struct tty *dhu_tty; /* what we work on */
+ int dhu_state; /* to manage TX output status */
+ int dhu_txaddr; /* UBA map address to TX buf */
+ short dhu_cc; /* character count on TX */
+ short dhu_modem; /* modem bits state */
+ } sc_dhu[NDHULINE];
+};
+
+#define IS_DHU 16 /* Unibus DHU-11 board linecount */
+#define IS_DHV 8 /* Q-bus DHV-11 or DHQ-11 */
+
+#define STATE_IDLE 000 /* no current output in progress */
+#define STATE_DMA_RUNNING 001 /* DMA TX in progress */
+#define STATE_DMA_STOPPED 002 /* DMA TX was aborted */
+#define STATE_TX_ONE_CHAR 004 /* did a single char directly */
+
+/* Flags used to monitor modem bits, make them understood outside driver */
+
+#define DML_DTR TIOCM_DTR
+#define DML_RTS TIOCM_RTS
+#define DML_CTS TIOCM_CTS
+#define DML_DCD TIOCM_CD
+#define DML_RI TIOCM_RI
+#define DML_DSR TIOCM_DSR
+#define DML_BRK 0100000 /* no equivalent, we will mask */
+
+/* On a stock DHV, channel pairs (0/1, 2/3, etc.) must use */
+/* a baud rate from the same group. So limiting to B is likely */
+/* best, although clone boards like the ABLE QHV allow all settings. */
+
+static struct speedtab dhuspeedtab[] = {
+ { 0, 0 }, /* Groups */
+ { 50, DHU_LPR_B50 }, /* A */
+ { 75, DHU_LPR_B75 }, /* B */
+ { 110, DHU_LPR_B110 }, /* A and B */
+ { 134, DHU_LPR_B134 }, /* A and B */
+ { 150, DHU_LPR_B150 }, /* B */
+ { 300, DHU_LPR_B300 }, /* A and B */
+ { 600, DHU_LPR_B600 }, /* A and B */
+ { 1200, DHU_LPR_B1200 }, /* A and B */
+ { 1800, DHU_LPR_B1800 }, /* B */
+ { 2000, DHU_LPR_B2000 }, /* B */
+ { 2400, DHU_LPR_B2400 }, /* A and B */
+ { 4800, DHU_LPR_B4800 }, /* A and B */
+ { 7200, DHU_LPR_B7200 }, /* A */
+ { 9600, DHU_LPR_B9600 }, /* A and B */
+ { 19200, DHU_LPR_B19200 }, /* B */
+ { 38400, DHU_LPR_B38400 }, /* A */
+ { -1, -1 }
+};
+
+static int dhu_match __P((struct device *, struct cfdata *, void *));
+static void dhu_attach __P((struct device *, struct device *, void *));
+static void dhurint __P((int));
+static void dhuxint __P((int));
+static void dhustart __P((struct tty *));
+static int dhuparam __P((struct tty *, struct termios *));
+static int dhuiflow __P((struct tty *, int));
+static unsigned dhumctl __P((struct dhu_softc *,int, int, int));
+ int dhuopen __P((dev_t, int, int, struct proc *));
+ int dhuclose __P((dev_t, int, int, struct proc *));
+ int dhuread __P((dev_t, struct uio *, int));
+ int dhuwrite __P((dev_t, struct uio *, int));
+ int dhuioctl __P((dev_t, u_long, caddr_t, int, struct proc *));
+ void dhustop __P((struct tty *, int));
+struct tty * dhutty __P((dev_t));
+
+struct cfattach dhu_ca = {
+ sizeof(struct dhu_softc), dhu_match, dhu_attach
+};
+
+extern struct cfdriver dhu_cd;
+
+/* Autoconfig handles: setup the controller to interrupt, */
+/* then complete the housecleaning for full operation */
+
+static int
+dhu_match(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+{
+ struct uba_attach_args *ua = aux;
+ register dhuregs *dhuaddr;
+ register int n;
+
+ dhuaddr = (dhuregs *) ua->ua_addr;
+
+ /* Reset controller to initialize, enable TX/RX interrupts */
+ /* to catch floating vector info elsewhere when completed */
+
+ dhuaddr->dhu_csr = (DHU_CSR_MASTER_RESET | DHU_CSR_RXIE | DHU_CSR_TXIE);
+
+ /* Now wait up to 3 seconds for self-test to complete. */
+
+ for (n = 0; n < 300; n++) {
+ DELAY(10000);
+ if ((dhuaddr->dhu_csr & DHU_CSR_MASTER_RESET) == 0)
+ break;
+ }
+
+ /* If the RESET did not clear after 3 seconds, */
+ /* the controller must be broken. */
+
+ if (n >= 300)
+ return 0;
+
+ /* Check whether diagnostic run has signalled a failure. */
+
+ if ((dhuaddr->dhu_csr & DHU_CSR_DIAG_FAIL) != 0)
+ return 0;
+
+ /* Register the RX interrupt handler */
+
+ ua->ua_ivec = dhurint;
+
+ return 1;
+}
+
+static void
+dhu_attach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
+{
+ register struct dhu_softc *sc = (void *)self;
+ register struct uba_attach_args *ua = aux;
+ register dhuregs *dhuaddr;
+ register unsigned c;
+ register int n;
+
+ dhuaddr = (dhuregs *) ua->ua_addr;
+
+ /* Process the 8 bytes of diagnostic info put into */
+ /* the FIFO following the master reset operation. */
+
+ printf("\n%s:", self->dv_xname);
+ for (n = 0; n < 8; n++) {
+ c = dhuaddr->dhu_rbuf;
+
+ if ((c&DHU_DIAG_CODE) == DHU_DIAG_CODE) {
+ if ((c&0200) == 0000)
+ printf(" rom(%d) version %d",
+ ((c>>1)&01), ((c>>2)&037));
+ else if (((c>>2)&07) != 0)
+ printf(" diag-error(proc%d)=%x",
+ ((c>>1)&01), ((c>>2)&07));
+ }
+ }
+ printf("\n");
+
+ c = dhuaddr->dhu_stat; /* get flag to distinguish DHU from DHV */
+
+ sc->sc_addr = dhuaddr;
+ sc->sc_type = (c & DHU_STAT_DHU)? IS_DHU: IS_DHV;
+
+ /* Now stuff TX interrupt handler in place */
+ scb_vecalloc(ua->ua_cvec + 4, dhuxint, self->dv_unit, SCB_ISTACK);
+}
+
+/* Receiver Interrupt */
+
+static void
+dhurint(unit)
+ int unit;
+{
+ struct dhu_softc *sc = dhu_cd.cd_devs[unit];
+ register dhuregs *dhuaddr;
+ register struct tty *tp;
+ register int cc, line;
+ register unsigned c, delta;
+ int overrun = 0;
+
+ dhuaddr = sc->sc_addr;
+
+ while ((c = dhuaddr->dhu_rbuf) & DHU_RBUF_DATA_VALID) {
+
+ /* Ignore diagnostic FIFO entries. */
+
+ if ((c & DHU_DIAG_CODE) == DHU_DIAG_CODE)
+ continue;
+
+ cc = c & 0xFF;
+ line = DHU_LINE(c>>8);
+ tp = sc->sc_dhu[line].dhu_tty;
+
+ /* LINK.TYPE is set so we get modem control FIFO entries */
+
+ if ((c & DHU_DIAG_CODE) == DHU_MODEM_CODE) {
+ c = (c << 8);
+ /* Do MDMBUF flow control, wakeup sleeping opens */
+ if (c & DHU_STAT_DCD) {
+ if (!(tp->t_state & TS_CARR_ON))
+ (void)(*linesw[tp->t_line].l_modem)(tp, 1);
+ }
+ else if ((tp->t_state & TS_CARR_ON) &&
+ (*linesw[tp->t_line].l_modem)(tp, 0) == 0)
+ (void) dhumctl(sc, line, 0, DMSET);
+
+ /* Do CRTSCTS flow control */
+ delta = c ^ sc->sc_dhu[line].dhu_modem;
+ sc->sc_dhu[line].dhu_modem = c;
+ if ((delta & DHU_STAT_CTS) &&
+ (tp->t_state & TS_ISOPEN) &&
+ (tp->t_cflag & CRTSCTS)) {
+ if (c & DHU_STAT_CTS) {
+ tp->t_state &= ~TS_TTSTOP;
+ ttstart(tp);
+ } else {
+ tp->t_state |= TS_TTSTOP;
+ dhustop(tp, 0);
+ }
+ }
+ continue;
+ }
+
+ if (!(tp->t_state & TS_ISOPEN)) {
+ wakeup((caddr_t)&tp->t_rawq);
+ continue;
+ }
+
+ if ((c & DHU_RBUF_OVERRUN_ERR) && overrun == 0) {
+ log(LOG_WARNING, "%s: silo overflow, line %d\n",
+ sc->sc_dev.dv_xname, line);
+ overrun = 1;
+ }
+ /* A BREAK key will appear as a NULL with a framing error */
Home |
Main Index |
Thread Index |
Old Index