Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/arm26 First attempt at an EtherH driver. Can just ...



details:   https://anonhg.NetBSD.org/src/rev/34b696beae77
branches:  trunk
changeset: 499894:34b696beae77
user:      bjh21 <bjh21%NetBSD.org@localhost>
date:      Fri Dec 01 14:28:36 2000 +0000

description:
First attempt at an EtherH driver.  Can just about transmit and receive
packets.  Interrupt enabling is left to the RISC OS driver, medium selection
is untested and it's hard-wired to the MAC address of my card.  Not really
for production use.

diffstat:

 sys/arch/arm26/conf/files.arm26     |    7 +-
 sys/arch/arm26/podulebus/if_eh.c    |  698 ++++++++++++++++++++++++++++++++++++
 sys/arch/arm26/podulebus/if_ehreg.h |   26 +
 3 files changed, 730 insertions(+), 1 deletions(-)

diffs (truncated from 753 to 300 lines):

diff -r d031bb0a6e5d -r 34b696beae77 sys/arch/arm26/conf/files.arm26
--- a/sys/arch/arm26/conf/files.arm26   Fri Dec 01 13:49:35 2000 +0000
+++ b/sys/arch/arm26/conf/files.arm26   Fri Dec 01 14:28:36 2000 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.arm26,v 1.6 2000/09/18 20:51:15 bjh21 Exp $
+# $NetBSD: files.arm26,v 1.7 2000/12/01 14:28:36 bjh21 Exp $
 
 # Copyright (c) 1997, 1998, 2000 Ben Harris
 # All rights reserved.
@@ -171,6 +171,11 @@
 attach ea at podulebus
 file   arch/arm26/podulebus/if_ea.c            ea
 
+# i-cubed EtherLAN 100, 200 and 500
+device eh: ether, ifnet, arp, dp8390nic
+attach eh at podulebus
+file   arch/arm26/podulebus/if_eh.c            eh
+
 # D.T. software IDE
 device dtide {[channel = -1]}: wdc_base, ata, atapi
 attach dtide at podulebus
diff -r d031bb0a6e5d -r 34b696beae77 sys/arch/arm26/podulebus/if_eh.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm26/podulebus/if_eh.c  Fri Dec 01 14:28:36 2000 +0000
@@ -0,0 +1,698 @@
+/* $NetBSD: if_eh.c,v 1.1 2000/12/01 14:28:37 bjh21 Exp $ */
+
+/*-
+ * Copyright (c) 2000 Ben Harris
+ * Copyright (c) 1997, 1998 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.
+ */
+/*
+ * Copyright (c) 1994, 1995 Charles M. Hannum.  All rights reserved.
+ *
+ * Copyright (C) 1993, David Greenman.  This software may be used, modified,
+ * copied, distributed, and sold, in both source and binary form provided that
+ * the above copyright and these terms are retained.  Under no circumstances is
+ * the author responsible for the proper functioning of this software, nor does
+ * the author assume any responsibility for damages incurred with its use.
+ */
+/* This file is part of NetBSD/arm26 -- a port of NetBSD to ARM2/3 machines. */
+/*
+ * if_eh.c -- driver for i-cubed EtherLan 100-, 200- and 500-series cards.
+ */
+
+#include <sys/param.h>
+
+__KERNEL_RCSID(0, "$NetBSD: if_eh.c,v 1.1 2000/12/01 14:28:37 bjh21 Exp $");
+
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/socket.h>
+#include <sys/mbuf.h>
+#include <sys/reboot.h>
+#include <sys/syslog.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+#include <net/if_media.h>
+
+#include <net/if_ether.h>
+
+#include <machine/bswap.h>
+#include <machine/bus.h>
+#include <machine/bus.h>
+#include <machine/irq.h>
+
+#ifndef __BUS_SPACE_HAS_STREAM_METHODS
+#define        bus_space_write_stream_2        bus_space_write_2
+#define        bus_space_write_multi_stream_2  bus_space_write_multi_2
+#define        bus_space_read_multi_stream_2   bus_space_read_multi_2
+#endif /* __BUS_SPACE_HAS_STREAM_METHODS */
+
+#include <dev/ic/dp8390reg.h>
+#include <dev/ic/dp8390var.h>
+
+#include <arch/arm26/podulebus/podulebus.h>
+#include <arch/arm32/podulebus/podules.h>
+#include <arch/arm26/podulebus/if_ehreg.h>
+
+#if BYTE_ORDER == BIG_ENDIAN
+#include <machine/bswap.h>
+#endif
+
+struct eh_softc {
+       struct  dp8390_softc sc_dp;
+       bus_space_tag_t         sc_datat;
+       bus_space_handle_t      sc_datah;
+       bus_space_tag_t         sc_ctlt;
+       bus_space_handle_t      sc_ctlh;
+       struct          irq_handler *sc_ih;
+       int                     sc_flags;
+#define EHF_16BIT      0x01
+       int                     sc_type;
+       u_int8_t                sc_ctrl; /* Current control reg state */
+};
+
+int    eh_write_mbuf(struct dp8390_softc *, struct mbuf *, int);
+int    eh_ring_copy(struct dp8390_softc *, int, caddr_t, u_short);
+void   eh_read_hdr(struct dp8390_softc *, int, struct dp8390_ring *);
+int    eh_test_mem(struct dp8390_softc *);
+
+void   eh_writemem(struct eh_softc *, u_int8_t *, int, size_t);
+void   eh_readmem(struct eh_softc *, int, u_int8_t *, size_t);
+static void eh_init_card(struct dp8390_softc *);
+
+/* if_media glue */
+static int eh_mediachange(struct dp8390_softc *);
+static void eh_mediastatus(struct dp8390_softc *, struct ifmediareq *);
+
+/* autoconfiguration glue */
+static int eh_match(struct device *, struct cfdata *, void *);
+static void eh_attach(struct device *, struct device *, void *);
+
+struct cfattach eh_ca = {
+       sizeof(struct eh_softc), eh_match, eh_attach
+};
+
+static int
+eh_match(struct device *parent, struct cfdata *cf, void *aux)
+{
+       struct podulebus_attach_args *pa = aux;
+
+       switch (pa->pa_product) {
+       case PODULE_ICUBED_ETHERLAN100:
+       case PODULE_ICUBED_ETHERLAN100AEH:
+       case PODULE_ICUBED_ETHERLAN200:
+       case PODULE_ICUBED_ETHERLAN200AEH:
+       case PODULE_ICUBED_ETHERLAN500:
+       case PODULE_ICUBED_ETHERLAN500AEH:
+               return 1;
+       }
+       return 0;
+}
+
+static const u_int8_t demo_addr_100[] = { 0x00, 0xc0, 0x32, 0x00, 0x84, 0x57 };
+static const u_int8_t demo_addr_200[] = { 0x00, 0xc0, 0x32, 0x00, 0x17, 0xbf };
+
+static void
+eh_attach(struct device *parent, struct device *self, void *aux)
+{
+       struct podulebus_attach_args *pa = aux;
+       struct eh_softc *sc = (struct eh_softc *)self;
+       struct dp8390_softc *dsc = &sc->sc_dp;
+       /* XXX Not all cards really support all media */
+       /* XXX 10baseFL on E513 */
+       int media[] =
+           { IFM_ETHER | IFM_AUTO,
+             IFM_ETHER | IFM_10_2,
+             IFM_ETHER | IFM_10_T};
+       int i;
+
+       /* Canonicalise card type. */
+       switch (pa->pa_product) {
+       case PODULE_ICUBED_ETHERLAN100:
+       case PODULE_ICUBED_ETHERLAN100AEH:
+               sc->sc_type = PODULE_ICUBED_ETHERLAN100;
+               break;
+       case PODULE_ICUBED_ETHERLAN200:
+       case PODULE_ICUBED_ETHERLAN200AEH:
+               sc->sc_type = PODULE_ICUBED_ETHERLAN200;
+               break;
+       case PODULE_ICUBED_ETHERLAN500:
+       case PODULE_ICUBED_ETHERLAN500AEH:
+               sc->sc_type = PODULE_ICUBED_ETHERLAN500;
+               break;
+       }
+
+       /* Memory size and width varies. */
+       dsc->mem_start = 0;
+       switch (sc->sc_type) {
+       case PODULE_ICUBED_ETHERLAN100:
+       case PODULE_ICUBED_ETHERLAN200:
+               printf(": 8-bit, 32 KB RAM\n");
+               dsc->mem_size  = 0x8000;
+               break;
+       case PODULE_ICUBED_ETHERLAN500:
+               printf(": 16-bit, 64 KB RAM\n");
+               sc->sc_flags |= EHF_16BIT;
+               dsc->mem_size = 0x10000;
+               break;
+       }
+
+       /* Set up bus spaces */
+       dsc->sc_regt = pa->pa_memc_t;
+       bus_space_subregion(dsc->sc_regt, pa->pa_memc_h, EH_DP8390, 0x10,
+           &dsc->sc_regh);
+       sc->sc_datat = pa->pa_memc_t;
+       bus_space_subregion(sc->sc_datat, pa->pa_memc_h, EH_DATA, 1,
+           &sc->sc_datah);
+       sc->sc_ctlt = pa->pa_fast_t;
+       bus_space_subregion(sc->sc_ctlt, pa->pa_fast_h, EH_CTRL, 1,
+           &sc->sc_ctlt);
+
+       /* dsc->cr_proto? */
+       /* dsc->rcr_proto? */
+
+       /* Follow NE2000 driver here. */
+        dsc->dcr_reg = ED_DCR_FT1 | ED_DCR_LS;
+       if (sc->sc_flags & EHF_16BIT)
+               dsc->dcr_reg |= ED_DCR_WTS;
+
+       /* Set up callbacks */
+       dsc->test_mem = eh_test_mem;
+       dsc->init_card = eh_init_card;
+       dsc->read_hdr = eh_read_hdr;
+       /* dsc->recv_int */
+       dsc->ring_copy = eh_ring_copy;
+       dsc->write_mbuf = eh_write_mbuf;
+       /* dsc->sc_enable */
+       /* dsc->sc_disable */
+       dsc->sc_mediachange = eh_mediachange;
+       dsc->sc_mediastatus = eh_mediastatus;
+
+       for (i = 0; i < 16; i++)
+               dsc->sc_reg_map[i] = i;
+
+       sc->sc_ctrl = 0xff;
+
+       /* XXX XXX XXX Ethernet address */
+       switch (sc->sc_type) {
+       case PODULE_ICUBED_ETHERLAN100:
+               memcpy(dsc->sc_enaddr, demo_addr_100, ETHER_ADDR_LEN);
+               break;
+       case PODULE_ICUBED_ETHERLAN200:
+               memcpy(dsc->sc_enaddr, demo_addr_200, ETHER_ADDR_LEN);
+               break;
+       }
+       printf("%s: rigged demo mode\n", self->dv_xname);
+
+       dp8390_config(dsc, media, sizeof(media) / sizeof(media[0]),
+           IFM_ETHER | IFM_AUTO);
+       dp8390_stop(dsc);
+
+#if 0
+       printf("%s: CR=%02x CLDA0=%02x CLDA1=%02x BNRY=%02x TSR=%02x "
+           "NCR=%02x FIFO=%02x ISR=%02x\n", self->dv_xname,
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CR),
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CLDA0),
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CLDA1),
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_BNRY),
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_TSR),
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_NCR),
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_FIFO),
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_ISR));
+       printf("%s: CRDA0=%02x CRDA1=%02x RSR=%02x CNTR0=%02x CNTR1=%02x "
+           "CNTR2=%02x\n", self->dv_xname,
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CRDA0),
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CRDA1),
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_RSR),
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CNTR0),
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CNTR1),
+           bus_space_read_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CNTR2));
+#endif
+
+       sc->sc_ih = podulebus_irq_establish(self->dv_parent, pa->pa_slotnum,
+                                           IPL_NET, dp8390_intr, self);
+       if (bootverbose)
+               printf("%s: interrupting at %s\n",
+                      self->dv_xname, irq_string(sc->sc_ih));
+       sc->sc_ctrl |= EH_CTRL_IE;
+       bus_space_write_1(sc->sc_ctlt, sc->sc_ctlh, 0, sc->sc_ctrl);
+}
+
+static void
+eh_init_card(struct dp8390_softc *sc)



Home | Main Index | Thread Index | Old Index