Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/vax/boot/boot Standalone driver for the Digital Equ...



details:   https://anonhg.NetBSD.org/src/rev/4580ab03f492
branches:  trunk
changeset: 486421:4580ab03f492
user:      ragge <ragge%NetBSD.org@localhost>
date:      Sun May 21 20:17:43 2000 +0000

description:
Standalone driver for the Digital Equipment Unibus Network Adapter (DEUNA).
This allows 11/750 owners to install from a single TU58 cassette.
(Are there still any 11/750 owners left out there? :-)

diffstat:

 sys/arch/vax/boot/boot/Makefile   |    4 +-
 sys/arch/vax/boot/boot/conf.c     |    4 +-
 sys/arch/vax/boot/boot/if_de.c    |  291 ++++++++++++++++++++++++++++++++++++++
 sys/arch/vax/boot/boot/vaxstand.h |    4 +-
 4 files changed, 299 insertions(+), 4 deletions(-)

diffs (truncated from 354 to 300 lines):

diff -r 2cb25f6bf05b -r 4580ab03f492 sys/arch/vax/boot/boot/Makefile
--- a/sys/arch/vax/boot/boot/Makefile   Sun May 21 18:53:54 2000 +0000
+++ b/sys/arch/vax/boot/boot/Makefile   Sun May 21 20:17:43 2000 +0000
@@ -1,11 +1,11 @@
-#      $NetBSD: Makefile,v 1.6 2000/05/20 13:36:11 ragge Exp $
+#      $NetBSD: Makefile,v 1.7 2000/05/21 20:17:44 ragge Exp $
 
 S=     ${.CURDIR}/../../../../
 
 PROG=  boot
 NOMAN= 1
 WARNS?=        1
-DEVS=  hp.c ctu.c ra.c mfm.c if_qe.c if_le.c if_ze.c
+DEVS=  hp.c ctu.c ra.c mfm.c if_qe.c if_le.c if_ze.c if_de.c
 SRCS=  srt0.s boot.c devopen.c conf.c autoconf.c netio.c rom.c romread.s \
        urem.s udiv.s consio.c str.s ${DEVS} findcpu.c
 
diff -r 2cb25f6bf05b -r 4580ab03f492 sys/arch/vax/boot/boot/conf.c
--- a/sys/arch/vax/boot/boot/conf.c     Sun May 21 18:53:54 2000 +0000
+++ b/sys/arch/vax/boot/boot/conf.c     Sun May 21 20:17:43 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: conf.c,v 1.7 2000/05/20 13:35:07 ragge Exp $ */
+/*     $NetBSD: conf.c,v 1.8 2000/05/21 20:17:43 ragge Exp $ */
 /*
  * Copyright (c) 1994 Ludd, University of Lule}, Sweden.
  * All rights reserved.
@@ -58,6 +58,7 @@
        SADEV("le",nodev, leopen, leclose, noioctl), /* LANCE */
         SADEV("ze",nodev, zeopen, zeclose, noioctl), /* SGEC */
        SADEV("rl",romstrategy, romopen, nullsys, noioctl),
+       SADEV("de",nodev, deopen, declose, noioctl), /* DEUNA */
 };
 
 int    cnvtab[] = {
@@ -73,6 +74,7 @@
        BDEV_LE,
        BDEV_ZE,
        BDEV_RL,
+       BDEV_DE,
 };
 
 int     ndevs = (sizeof(devsw)/sizeof(devsw[0]));
diff -r 2cb25f6bf05b -r 4580ab03f492 sys/arch/vax/boot/boot/if_de.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/vax/boot/boot/if_de.c    Sun May 21 20:17:43 2000 +0000
@@ -0,0 +1,291 @@
+/*     $NetBSD: if_de.c,v 1.1 2000/05/21 20:17:44 ragge Exp $  */
+
+/*
+ * Copyright (c) 2000 Ludd, University of Lule}, Sweden. All rights reserved.
+ *
+ * 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 at Ludd, University of
+ *      Lule}, Sweden and its contributors.
+ * 4. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ *
+ *     Standalone routine for the DEUNA Ethernet controller.
+ */
+
+#include <sys/param.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/queue.h>
+
+#include <net/if.h>
+#include <net/if_ether.h>
+
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+
+#include <lib/libsa/netif.h>
+#include <lib/libsa/stand.h>
+
+#include "lib/libkern/libkern.h"
+
+#include <dev/qbus/if_dereg.h>
+
+#include "arch/vax/include/sid.h"
+#include "arch/vax/include/rpb.h"
+#include "arch/vax/include/pte.h"
+
+#include "vaxstand.h"
+
+static int de_get(struct iodesc *, void *, size_t, time_t);
+static int de_put(struct iodesc *, void *, size_t);
+static void dewait(char *);
+
+struct netif_driver de_driver = {
+       0, 0, 0, 0, de_get, de_put,
+};
+
+#define NRCV 8         /* allocate 8 receive descriptors */
+#define NXMT 4         /* and 4 transmit - must be >1 */
+
+struct de_cdata {
+       /* the following structures are always mapped in */
+        struct  de_pcbb dc_pcbb;        /* port control block */
+        struct  de_ring dc_xrent[NXMT]; /* transmit ring entrys */
+        struct  de_ring dc_rrent[NRCV]; /* receive ring entrys */
+        struct  de_udbbuf dc_udbbuf;    /* UNIBUS data buffer */
+       char    dc_rbuf[NRCV][ETHER_MAX_LEN];
+       char    dc_xbuf[NXMT][ETHER_MAX_LEN];
+        /* end mapped area */
+};
+
+static volatile struct de_cdata *dc, *pdc;
+static volatile char *addr;
+static int crx, ctx;
+#define DE_WCSR(csr, val) *(volatile u_short *)(addr + (csr)) = (val)
+#define DE_WLOW(val) *(volatile u_char *)(addr + DE_PCSR0) = (val)
+#define DE_WHIGH(val) *(volatile u_char *)(addr + DE_PCSR0 + 1) = (val)
+#define DE_RCSR(csr) *(volatile u_short *)(addr + (csr))
+#define LOWORD(x)       ((u_int)(x) & 0xffff)
+#define HIWORD(x)       (((u_int)(x) >> 16) & 0x3)
+#define        dereg(x)        ((x) & 017777)
+
+int
+deopen(struct open_file *f, int adapt, int ctlr, int unit, int part)
+{
+       int i, cdata, *map, npgs;
+       char eaddr[6];
+
+       /* point to the device in memory */
+       if (askname == 0) /* Override if autoboot */
+               addr = (char *)bootrpb.csrphy;
+       else {
+               addr = (char *)csrbase + dereg(0174510);
+               bootrpb.csrphy = (int)addr;
+       }
+#ifdef DEV_DEBUG
+       printf("deopen: csrbase %x addr %p nexaddr %x\n", 
+           csrbase, addr, nexaddr);
+#endif
+       /* reset the device and wait for completion */
+       DE_WCSR(DE_PCSR0, 0);
+       {volatile int j = 100; while (--j);}
+       DE_WCSR(DE_PCSR0, PCSR0_RSET);
+       dewait("reset");
+
+       /* Map in the control structures and buffers */
+       dc = alloc(sizeof(struct de_cdata));
+       (int)pdc = (int)dc & VAX_PGOFSET;
+       map = (int *)nexaddr + 512;
+       npgs = (sizeof(struct de_cdata) >> VAX_PGSHIFT) + 1;
+       cdata = (int)dc >> VAX_PGSHIFT;
+       for (i = 0; i < npgs; i++) {
+               map[i] = PG_V | (cdata + i);
+       }
+
+       bzero((char *)dc, sizeof(struct de_cdata));
+       
+       /* Tell the DEUNA about our PCB */
+       DE_WCSR(DE_PCSR2, LOWORD(pdc));
+       DE_WCSR(DE_PCSR3, HIWORD(pdc));
+       DE_WLOW(CMD_GETPCBB);
+       dewait("pcbb");
+
+       /* Get our address */
+       dc->dc_pcbb.pcbb0 = FC_RDPHYAD;
+       DE_WLOW(CMD_GETCMD);
+       dewait("read physaddr");
+       bcopy((char *)&dc->dc_pcbb.pcbb2, eaddr, 6);
+
+       /* Create and link the descriptors */
+       for (i=0; i < NRCV; i++) {
+               volatile struct de_ring *rp = &dc->dc_rrent[i];
+
+               rp->r_lenerr = 0;
+               rp->r_segbl = LOWORD(&pdc->dc_rbuf[i][0]);
+               rp->r_segbh = HIWORD(&pdc->dc_rbuf[i][0]);
+               rp->r_flags = RFLG_OWN;
+               rp->r_slen = ETHER_MAX_LEN;
+       }
+       for (i=0; i < NXMT; i++) {
+               volatile struct de_ring *rp = &dc->dc_xrent[i];
+
+               rp->r_segbl = LOWORD(&pdc->dc_xbuf[i][0]);
+               rp->r_segbh = HIWORD(&pdc->dc_xbuf[i][0]);
+               rp->r_tdrerr = 0;
+               rp->r_flags = 0;
+       }
+       crx = ctx = 0;
+
+       /* set the transmit and receive ring header addresses */
+       dc->dc_pcbb.pcbb0 = FC_WTRING;
+       dc->dc_pcbb.pcbb2 = LOWORD(&pdc->dc_udbbuf);
+       dc->dc_pcbb.pcbb4 = HIWORD(&pdc->dc_udbbuf);
+
+       dc->dc_udbbuf.b_tdrbl = LOWORD(&pdc->dc_xrent[0]);
+       dc->dc_udbbuf.b_tdrbh = HIWORD(&pdc->dc_xrent[0]);
+       dc->dc_udbbuf.b_telen = sizeof (struct de_ring) / sizeof(u_int16_t);
+       dc->dc_udbbuf.b_trlen = NXMT;
+       dc->dc_udbbuf.b_rdrbl = LOWORD(&pdc->dc_rrent[0]);
+       dc->dc_udbbuf.b_rdrbh = HIWORD(&pdc->dc_rrent[0]);
+       dc->dc_udbbuf.b_relen = sizeof (struct de_ring) / sizeof(u_int16_t);
+       dc->dc_udbbuf.b_rrlen = NRCV;
+
+       DE_WLOW(CMD_GETCMD);
+       dewait("wtring");
+
+       dc->dc_pcbb.pcbb0 = FC_WTMODE;
+       dc->dc_pcbb.pcbb2 = MOD_DRDC|MOD_TPAD|MOD_HDX;
+       DE_WLOW(CMD_GETCMD);
+       dewait("wtmode");
+
+       DE_WLOW(CMD_START);
+       dewait("start");
+
+       DE_WLOW(CMD_PDMD);
+       dewait("initpoll");
+       /* Should be running by now */
+
+       net_devinit(f, &de_driver, eaddr);
+
+       return 0;
+}
+
+int
+de_get(struct iodesc *desc, void *pkt, size_t maxlen, time_t timeout)
+{
+       volatile int to = 100000 * timeout;
+       int len, csr0;
+
+       if ((csr0 = DE_RCSR(DE_PCSR0)) & PCSR0_INTR)
+               DE_WHIGH(csr0 >> 8);
+retry:
+       if (to-- == 0)
+               return 0;
+
+       if (dc->dc_rrent[crx].r_flags & RFLG_OWN)
+               goto retry;
+
+       if (dc->dc_rrent[crx].r_flags & RFLG_ERRS)
+               len = 0;
+       else
+               len = dc->dc_rrent[crx].r_lenerr & RERR_MLEN;
+
+       if (len > maxlen)
+               len = maxlen;
+       if (len)
+               bcopy((char *)&dc->dc_rbuf[crx][0], pkt, len);
+
+       dc->dc_rrent[crx].r_flags = RFLG_OWN;
+       dc->dc_rrent[crx].r_lenerr = 0;
+#ifdef DEV_DEBUG
+       printf("Got packet: len %d idx %d maxlen %d\n", len, crx, maxlen);
+#endif
+       if (++crx == NRCV)
+               crx = 0;
+
+       if (len == 0)
+               goto retry;
+       return len;
+}
+
+
+int
+de_put(struct iodesc *desc, void *pkt, size_t len)
+{
+       volatile int to = 100000;
+       int csr0;
+
+       if ((csr0 = DE_RCSR(DE_PCSR0)) & PCSR0_INTR)
+               DE_WHIGH(csr0 >> 8);
+#ifdef DEV_DEBUG
+       printf("de_put: len %d\n", len);
+#endif
+retry:
+       if (to-- == 0)
+               return -1;
+
+       if (dc->dc_xrent[ctx].r_flags & RFLG_OWN)
+               goto retry;
+
+       bcopy(pkt, (char *)&dc->dc_xbuf[ctx][0], len);
+
+       dc->dc_xrent[ctx].r_slen = len;
+       dc->dc_xrent[ctx].r_tdrerr = 0;
+       dc->dc_xrent[ctx].r_flags = XFLG_OWN|XFLG_STP|XFLG_ENP;



Home | Main Index | Thread Index | Old Index