Source-Changes-HG archive

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

[src/trunk]: src/sys Driver for Sun GEM gigabit ethernet, Sun ERI 10/100, and...



details:   https://anonhg.NetBSD.org/src/rev/958b1347654a
branches:  trunk
changeset: 515021:958b1347654a
user:      eeh <eeh%NetBSD.org@localhost>
date:      Sun Sep 16 00:11:41 2001 +0000

description:
Driver for Sun GEM gigabit ethernet, Sun ERI 10/100, and Apple GMAC.

diffstat:

 sys/conf/files           |     6 +-
 sys/dev/ic/gem.c         |  2033 ++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/ic/gemreg.h      |   533 ++++++++++++
 sys/dev/ic/gemvar.h      |   321 +++++++
 sys/dev/pci/files.pci    |     6 +-
 sys/dev/pci/if_gem_pci.c |   189 ++++
 6 files changed, 3086 insertions(+), 2 deletions(-)

diffs (truncated from 3132 to 300 lines):

diff -r bd79fe253488 -r 958b1347654a sys/conf/files
--- a/sys/conf/files    Sun Sep 16 00:01:15 2001 +0000
+++ b/sys/conf/files    Sun Sep 16 00:11:41 2001 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.460 2001/09/15 20:36:35 chs Exp $
+#      $NetBSD: files,v 1.461 2001/09/16 00:11:41 eeh Exp $
 
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
@@ -365,6 +365,10 @@
 device hme: arp, ether, ifnet, mii
 file   dev/ic/hme.c                    hme
 
+# Sun GEM Ethernet controllers
+device gem: arp, ether, ifnet, mii
+file   dev/ic/gem.c                    gem
+
 # 8390-family Ethernet controllers
 defopt opt_ipkdb.h     IPKDB_DP8390                            : IPKDB
 define dp8390nic
diff -r bd79fe253488 -r 958b1347654a sys/dev/ic/gem.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/gem.c  Sun Sep 16 00:11:41 2001 +0000
@@ -0,0 +1,2033 @@
+/*     $NetBSD: gem.c,v 1.1 2001/09/16 00:11:43 eeh Exp $ */
+
+/*
+ * 
+ * Copyright (C) 2001 Eduardo Horvath.
+ * 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.
+ *  
+ * 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.
+ *
+ */
+
+/*
+ * Driver for Sun GEM ethernet controllers.
+ */
+
+#define        GEM_DEBUG
+int gem_opdebug = 0;
+
+#include "bpfilter.h"
+
+#include <sys/param.h>
+#include <sys/systm.h> 
+#include <sys/callout.h>
+#include <sys/mbuf.h>   
+#include <sys/syslog.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 <machine/endian.h>
+
+#include <uvm/uvm_extern.h>
+ 
+#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 
+
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+#include <dev/mii/mii_bitbang.h>
+
+#include <dev/ic/gemreg.h>
+#include <dev/ic/gemvar.h>
+
+#define TRIES  10000
+
+void           gem_start __P((struct ifnet *));
+void           gem_stop __P((struct ifnet *, int));
+int            gem_ioctl __P((struct ifnet *, u_long, caddr_t));
+void           gem_tick __P((void *));
+void           gem_watchdog __P((struct ifnet *));
+void           gem_shutdown __P((void *));
+int            gem_init __P((struct ifnet *));
+void           gem_init_regs(struct gem_softc *sc);
+static int     gem_ringsize(int sz);
+int            gem_meminit __P((struct gem_softc *));
+void           gem_mifinit __P((struct gem_softc *));
+void           gem_reset __P((struct gem_softc *));
+int            gem_reset_rx(struct gem_softc *sc);
+int            gem_reset_tx(struct gem_softc *sc);
+int            gem_disable_rx(struct gem_softc *sc);
+int            gem_disable_tx(struct gem_softc *sc);
+void           gem_rxdrain(struct gem_softc *sc);
+int            gem_add_rxbuf(struct gem_softc *sc, int idx);
+void           gem_setladrf __P((struct gem_softc *));
+
+/* MII methods & callbacks */
+static int     gem_mii_readreg __P((struct device *, int, int));
+static void    gem_mii_writereg __P((struct device *, int, int, int));
+static void    gem_mii_statchg __P((struct device *));
+
+int            gem_mediachange __P((struct ifnet *));
+void           gem_mediastatus __P((struct ifnet *, struct ifmediareq *));
+
+struct mbuf    *gem_get __P((struct gem_softc *, int, int));
+int            gem_put __P((struct gem_softc *, int, struct mbuf *));
+void           gem_read __P((struct gem_softc *, int, int));
+int            gem_eint __P((struct gem_softc *, u_int));
+int            gem_rint __P((struct gem_softc *));
+int            gem_tint __P((struct gem_softc *));
+void           gem_power __P((int, void *));
+
+static int     ether_cmp __P((u_char *, u_char *));
+
+/* Default buffer copy routines */
+void   gem_copytobuf_contig __P((struct gem_softc *, void *, int, int));
+void   gem_copyfrombuf_contig __P((struct gem_softc *, void *, int, int));
+void   gem_zerobuf_contig __P((struct gem_softc *, int, int));
+
+
+#ifdef GEM_DEBUG
+#define        DPRINTF(sc, x)  if ((sc)->sc_ethercom.ec_if.if_flags & IFF_DEBUG) \
+                               printf x
+#else
+#define        DPRINTF(sc, x)  /* nothing */
+#endif
+
+
+/*
+ * gem_config:
+ *
+ *     Attach a Gem interface to the system.
+ */
+void
+gem_config(sc)
+       struct gem_softc *sc;
+{
+       struct ifnet *ifp = &sc->sc_ethercom.ec_if;
+       struct mii_data *mii = &sc->sc_mii;
+       struct mii_softc *child;
+       int i, error;
+
+       /* Make sure the chip is stopped. */
+       ifp->if_softc = sc;
+       gem_reset(sc);
+
+       /*
+        * Allocate the control data structures, and create and load the
+        * DMA map for it.
+        */
+       if ((error = bus_dmamem_alloc(sc->sc_dmatag,
+           sizeof(struct gem_control_data), PAGE_SIZE, 0, &sc->sc_cdseg,
+           1, &sc->sc_cdnseg, 0)) != 0) {
+               printf("%s: unable to allocate control data, error = %d\n",
+                   sc->sc_dev.dv_xname, error);
+               goto fail_0;
+       }
+
+/* XXX should map this in with correct endianness */
+       if ((error = bus_dmamem_map(sc->sc_dmatag, &sc->sc_cdseg, sc->sc_cdnseg,
+           sizeof(struct gem_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_dmatag,
+           sizeof(struct gem_control_data), 1,
+           sizeof(struct gem_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_dmatag, sc->sc_cddmamap,
+           sc->sc_control_data, sizeof(struct gem_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;
+       }
+
+       /*
+        * Initialize the transmit job descriptors.
+        */
+       SIMPLEQ_INIT(&sc->sc_txfreeq);
+       SIMPLEQ_INIT(&sc->sc_txdirtyq);
+
+       /*
+        * Create the transmit buffer DMA maps.
+        */
+       for (i = 0; i < GEM_TXQUEUELEN; i++) {
+               struct gem_txsoft *txs;
+
+               txs = &sc->sc_txsoft[i];
+               txs->txs_mbuf = NULL;
+               if ((error = bus_dmamap_create(sc->sc_dmatag, MCLBYTES,
+                   GEM_NTXSEGS, MCLBYTES, 0, 0,
+                   &txs->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;
+               }
+               SIMPLEQ_INSERT_TAIL(&sc->sc_txfreeq, txs, txs_q);
+       }
+
+       /*
+        * Create the receive buffer DMA maps.
+        */
+       for (i = 0; i < GEM_NRXDESC; i++) {
+               if ((error = bus_dmamap_create(sc->sc_dmatag, 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;
+       }
+
+       /*
+        * From this point forward, the attachment cannot fail.  A failure
+        * before this point releases all resources that may have been
+        * allocated.
+        */
+       sc->sc_flags |= GEMF_ATTACHED;
+
+       /* Announce ourselves. */
+       printf("%s: Ethernet address %s\n", sc->sc_dev.dv_xname,
+           ether_sprintf(sc->sc_enaddr));
+
+       /* Initialize ifnet structure. */
+       strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
+       ifp->if_softc = sc;
+       ifp->if_flags =
+           IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
+       ifp->if_start = gem_start;
+       ifp->if_ioctl = gem_ioctl;
+       ifp->if_watchdog = gem_watchdog;
+       ifp->if_stop = gem_stop;
+       ifp->if_init = gem_init;
+       IFQ_SET_READY(&ifp->if_snd);
+
+       /* Initialize ifmedia structures and MII info */
+       mii->mii_ifp = ifp;
+       mii->mii_readreg = gem_mii_readreg; 
+       mii->mii_writereg = gem_mii_writereg;
+       mii->mii_statchg = gem_mii_statchg;
+
+       ifmedia_init(&mii->mii_media, 0, gem_mediachange, gem_mediastatus);
+
+       gem_mifinit(sc);
+
+       mii_attach(&sc->sc_dev, mii, 0xffffffff,
+                       MII_PHY_ANY, MII_OFFSET_ANY, 0);
+
+       child = LIST_FIRST(&mii->mii_phys);
+       if (child == NULL) {
+               /* No PHY attached */
+               ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
+               ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
+       } else {
+               /*
+                * Walk along the list of attached MII devices and
+                * establish an `MII instance' to `phy number'
+                * mapping. We'll use this mapping in media change
+                * requests to determine which phy to use to program
+                * the MIF configuration register.
+                */
+               for (; child != NULL; child = LIST_NEXT(child, mii_list)) {
+                       /*
+                        * Note: we support just two PHYs: the built-in
+                        * internal device and an external on the MII
+                        * connector.
+                        */



Home | Main Index | Thread Index | Old Index