Source-Changes-HG archive

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

[src/trunk]: src/sys This is the long-awaited "new Tulip driver", a complete, ...



details:   https://anonhg.NetBSD.org/src/rev/4f523178010c
branches:  trunk
changeset: 475967:4f523178010c
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Sep 01 00:32:41 1999 +0000

description:
This is the long-awaited "new Tulip driver", a complete, from-scratch
rewrite of the driver for the DECchip 21x4x Ethernet chips, and a variety
of clones.

Currently, the driver supports the Winbond 89C840F (this works pretty
well), and the Lite-On PNIC (e.g. NetGear PCI boards), however Lite-On
support may be broken [I may simply have a busted test board].

Eventually, support for the Macronix and ASIX chips will filter into
this driver, and then, slowly, support for the genuine DEC chips,
and maybe even the DE-425 EISA model.

diffstat:

 sys/conf/files           |     6 +-
 sys/dev/ic/tulip.c       |  2447 ++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/ic/tulipreg.h    |   836 +++++++++++++++
 sys/dev/ic/tulipvar.h    |   347 ++++++
 sys/dev/pci/files.pci    |     6 +-
 sys/dev/pci/if_tlp_pci.c |   398 +++++++
 6 files changed, 4038 insertions(+), 2 deletions(-)

diffs (truncated from 4084 to 300 lines):

diff -r 8037d581f893 -r 4f523178010c sys/conf/files
--- a/sys/conf/files    Wed Sep 01 00:05:01 1999 +0000
+++ b/sys/conf/files    Wed Sep 01 00:32:41 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.313 1999/08/21 03:47:50 matt Exp $
+#      $NetBSD: files,v 1.314 1999/09/01 00:32:42 thorpej Exp $
 
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
@@ -369,6 +369,10 @@
 device  wdc: ata, atapi, wdc_base
 file    dev/ic/wdc.c wdc_base
 
+# DECchip 21x4x Ethernet controller family, and assorted clones.
+device tlp: arp, ether, ifnet, mii
+file   dev/ic/tulip.c                  tlp
+
 # Definitions for wscons
 # device attributes: display, display with emulator, keyboard, and mouse
 define  wsdisplaydev { }
diff -r 8037d581f893 -r 4f523178010c sys/dev/ic/tulip.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/tulip.c        Wed Sep 01 00:32:41 1999 +0000
@@ -0,0 +1,2447 @@
+/*     $NetBSD: tulip.c,v 1.1 1999/09/01 00:32:41 thorpej Exp $        */
+
+/*-
+ * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center.
+ *
+ * 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 NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+
+/*
+ * Device driver for the Digital Semiconductor ``Tulip'' (21x4x)
+ * Ethernet controller family, and a variety of clone chips.
+ */
+
+#include "opt_inet.h"
+#include "opt_ns.h"
+#include "bpfilter.h"
+
+#include <sys/param.h>
+#include <sys/systm.h> 
+#include <sys/mbuf.h>   
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/errno.h>
+#include <sys/device.h>
+
+#include <vm/vm.h>             /* for PAGE_SIZE */
+ 
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_media.h>
+#include <net/if_ether.h>
+
+#if NBPFILTER > 0 
+#include <net/bpf.h>
+#endif 
+
+#ifdef INET
+#include <netinet/in.h> 
+#include <netinet/if_inarp.h>
+#endif
+
+#ifdef NS
+#include <netns/ns.h>
+#include <netns/ns_if.h>
+#endif
+
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+
+#include <dev/ic/tulipreg.h>
+#include <dev/ic/tulipvar.h>
+
+/*
+ * The following tables compute the transmit threshold mode.  We start
+ * at index 0.  When ever we get a transmit underrun, we increment our
+ * index, falling back if we encounter the NULL terminator.
+ *
+ * Note: Store and forward mode is only available on the 100mbps chips
+ * (21140 and higher).
+ */
+const struct tulip_txthresh_tab tlp_10_txthresh_tab[] = {
+       { OPMODE_TR_72,         "72 bytes" },
+       { OPMODE_TR_96,         "96 bytes" },
+       { OPMODE_TR_128,        "128 bytes" },
+       { OPMODE_TR_160,        "160 bytes" },
+       { 0,                    NULL },
+};
+
+const struct tulip_txthresh_tab tlp_10_100_txthresh_tab[] = {
+       { OPMODE_TR_72,         "72/128 bytes" },
+       { OPMODE_TR_96,         "96/256 bytes" },
+       { OPMODE_TR_128,        "128/512 bytes" },
+       { OPMODE_TR_160,        "160/1024 bytes" },
+       { OPMODE_SF,            "store and forward mode" },
+       { 0,                    NULL },
+};
+
+void   tlp_start __P((struct ifnet *));
+void   tlp_watchdog __P((struct ifnet *));
+int    tlp_ioctl __P((struct ifnet *, u_long, caddr_t));
+
+void   tlp_shutdown __P((void *));
+
+void   tlp_reset __P((struct tulip_softc *));
+int    tlp_init __P((struct tulip_softc *));
+void   tlp_rxdrain __P((struct tulip_softc *));
+void   tlp_stop __P((struct tulip_softc *, int));
+int    tlp_add_rxbuf __P((struct tulip_softc *, int));
+void   tlp_idle __P((struct tulip_softc *, u_int32_t));
+void   tlp_srom_idle __P((struct tulip_softc *));
+
+void   tlp_filter_setup __P((struct tulip_softc *));
+void   tlp_winb_filter_setup __P((struct tulip_softc *));
+
+void   tlp_rxintr __P((struct tulip_softc *));
+void   tlp_txintr __P((struct tulip_softc *));
+
+void   tlp_mii_tick __P((void *));
+void   tlp_mii_statchg __P((struct device *));
+
+void   tlp_mii_getmedia __P((struct tulip_softc *, struct ifmediareq *));
+int    tlp_mii_setmedia __P((struct tulip_softc *));
+
+void   tlp_sio_mii_sync __P((struct tulip_softc *));
+void   tlp_sio_mii_sendbits __P((struct tulip_softc *, u_int32_t, int));
+int    tlp_sio_mii_readreg __P((struct device *, int, int));
+void   tlp_sio_mii_writereg __P((struct device *, int, int, int));
+
+int    tlp_pnic_mii_readreg __P((struct device *, int, int));
+void   tlp_pnic_mii_writereg __P((struct device *, int, int, int));
+
+u_int32_t tlp_crc32 __P((const u_int8_t *, size_t));
+#define        tlp_mchash(addr)        (tlp_crc32((addr), ETHER_ADDR_LEN) &    \
+                                (TULIP_MCHASHSIZE - 1))
+
+#ifdef TLP_DEBUG
+#define        DPRINTF(x)      printf x
+#else
+#define        DPRINTF(x)      /* nothing */
+#endif
+
+/*
+ * tlp_attach:
+ *
+ *     Attach a Tulip interface to the system.
+ */
+void
+tlp_attach(sc, name, enaddr)
+       struct tulip_softc *sc;
+       const char *name;
+       const u_int8_t *enaddr;
+{
+       struct ifnet *ifp = &sc->sc_ethercom.ec_if;
+       int i, rseg, error;
+       bus_dma_segment_t seg;
+
+       /*
+        * NOTE: WE EXPECT THE FRONT-END TO INITIALIZE sc_regshift!
+        */
+
+       /*
+        * Setup the transmit threshold table.
+        */
+       switch (sc->sc_chip) {
+       case TULIP_CHIP_DE425:
+       case TULIP_CHIP_21040:
+       case TULIP_CHIP_21041:
+               sc->sc_txth = tlp_10_txthresh_tab;
+               break;
+
+       default:
+               sc->sc_txth = tlp_10_100_txthresh_tab;
+               break;
+       }
+
+       /*
+        * Setup the filter setup function.
+        */
+       switch (sc->sc_chip) {
+       case TULIP_CHIP_WB89C840F:
+               sc->sc_filter_setup = tlp_winb_filter_setup;
+               break;
+
+       default:
+               sc->sc_filter_setup = tlp_filter_setup;
+               break;
+       }
+
+       SIMPLEQ_INIT(&sc->sc_txfreeq);
+       SIMPLEQ_INIT(&sc->sc_txdirtyq);
+
+       /*
+        * Allocate the control data structures, and create and load the
+        * DMA map for it.
+        */
+       if ((error = bus_dmamem_alloc(sc->sc_dmat,
+           sizeof(struct tulip_control_data), PAGE_SIZE, 0, &seg, 1, &rseg,
+           0)) != 0) {
+               printf("%s: unable to allocate control data, error = %d\n",
+                   sc->sc_dev.dv_xname, error);
+               goto fail_0;
+       }
+
+       if ((error = bus_dmamem_map(sc->sc_dmat, &seg, rseg,
+           sizeof(struct tulip_control_data), (caddr_t *)&sc->sc_control_data,
+           BUS_DMA_COHERENT)) != 0) {
+               printf("%s: unable to map control data, error = %d\n",
+                   sc->sc_dev.dv_xname, error);
+               goto fail_1;
+       }
+
+       if ((error = bus_dmamap_create(sc->sc_dmat,
+           sizeof(struct tulip_control_data), 1,
+           sizeof(struct tulip_control_data), 0, 0, &sc->sc_cddmamap)) != 0) {
+               printf("%s: unable to create control data DMA map, "
+                   "error = %d\n", sc->sc_dev.dv_xname, error);
+               goto fail_2;
+       }
+
+       if ((error = bus_dmamap_load(sc->sc_dmat, sc->sc_cddmamap,
+           sc->sc_control_data, sizeof(struct tulip_control_data), NULL,
+           0)) != 0) {
+               printf("%s: unable to load control data DMA map, error = %d\n",
+                   sc->sc_dev.dv_xname, error);
+               goto fail_3;
+       }
+
+       /*
+        * Create the transmit buffer DMA maps.
+        */
+       for (i = 0; i < TULIP_TXQUEUELEN; i++) {
+               if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES,
+                   TULIP_NTXSEGS, MCLBYTES, 0, 0,
+                   &sc->sc_txsoft[i].txs_dmamap)) != 0) {
+                       printf("%s: unable to create tx DMA map %d, "
+                           "error = %d\n", sc->sc_dev.dv_xname, i, error);
+                       goto fail_4;
+               }
+       }
+
+       /*
+        * Create the recieve buffer DMA maps.
+        */
+       for (i = 0; i < TULIP_NRXDESC; i++) {
+               if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
+                   MCLBYTES, 0, 0, &sc->sc_rxsoft[i].rxs_dmamap)) != 0) {
+                       printf("%s: unable to create rx DMA map %d, "
+                           "error = %d\n", sc->sc_dev.dv_xname, i, error);
+                       goto fail_5;
+               }
+               sc->sc_rxsoft[i].rxs_mbuf = NULL;
+       }
+
+       /*
+        * Reset the chip to a known state.
+        */
+       tlp_reset(sc);
+
+       /* Announce ourselves. */
+       printf("%s: %s%sEthernet address %s\n", sc->sc_dev.dv_xname,



Home | Main Index | Thread Index | Old Index