Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev Split we(4) driver to bus independant and ISA-specif...
details: https://anonhg.NetBSD.org/src/rev/4063ac3494f8
branches: trunk
changeset: 507497:4063ac3494f8
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Fri Mar 23 17:34:41 2001 +0000
description:
Split we(4) driver to bus independant and ISA-specific parts, in preparation
for MCA attachment.
diffstat:
sys/dev/ic/we.c | 624 ++++++++++++++++++++++++++++
sys/dev/ic/wereg.h | 231 ++++++++++
sys/dev/ic/wevar.h | 34 +
sys/dev/isa/if_we.c | 1016 -----------------------------------------------
sys/dev/isa/if_we_isa.c | 541 +++++++++++++++++++++++++
sys/dev/isa/if_wereg.h | 231 ----------
6 files changed, 1430 insertions(+), 1247 deletions(-)
diffs (truncated from 2701 to 300 lines):
diff -r ce3781ae1111 -r 4063ac3494f8 sys/dev/ic/we.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/we.c Fri Mar 23 17:34:41 2001 +0000
@@ -0,0 +1,624 @@
+/* $NetBSD: we.c,v 1.1 2001/03/23 17:34:41 jdolecek Exp $ */
+
+/*-
+ * 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.
+ */
+
+/*
+ * Device driver for National Semiconductor DS8390/WD83C690 based ethernet
+ * adapters.
+ *
+ * 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.
+ */
+
+/*
+ * Device driver for the Western Digital/SMC 8003 and 8013 series,
+ * and the SMC Elite Ultra (8216).
+ */
+
+#include "opt_inet.h"
+#include "opt_ns.h"
+#include "bpfilter.h"
+#include "rnd.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/socket.h>
+#include <sys/mbuf.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>
+
+#ifdef INET
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+#include <netinet/ip.h>
+#include <netinet/if_inarp.h>
+#endif
+
+#ifdef NS
+#include <netns/ns.h>
+#include <netns/ns_if.h>
+#endif
+
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#include <net/bpfdesc.h>
+#endif
+
+#include <machine/bus.h>
+#include <machine/bswap.h>
+#include <machine/intr.h>
+
+#include <dev/isa/isareg.h>
+#include <dev/isa/isavar.h>
+
+#include <dev/ic/dp8390reg.h>
+#include <dev/ic/dp8390var.h>
+#include <dev/ic/wereg.h>
+#include <dev/ic/wevar.h>
+
+#ifndef __BUS_SPACE_HAS_STREAM_METHODS
+#define bus_space_read_region_stream_2 bus_space_read_region_2
+#define bus_space_write_stream_2 bus_space_write_2
+#define bus_space_write_region_stream_2 bus_space_write_region_2
+#endif
+
+static void we_set_media __P((struct we_softc *, int));
+
+static void we_media_init __P((struct dp8390_softc *));
+
+static int we_mediachange __P((struct dp8390_softc *));
+static void we_mediastatus __P((struct dp8390_softc *, struct ifmediareq *));
+
+static void we_recv_int __P((struct dp8390_softc *));
+static void we_init_card __P((struct dp8390_softc *));
+static int we_write_mbuf __P((struct dp8390_softc *, struct mbuf *, int));
+static int we_ring_copy __P((struct dp8390_softc *, int, caddr_t, u_short));
+static void we_read_hdr __P((struct dp8390_softc *, int, struct dp8390_ring *));
+static int we_test_mem __P((struct dp8390_softc *));
+
+static __inline void we_readmem __P((struct we_softc *, int, u_int8_t *, int));
+
+/*
+ * Delay needed when switching 16-bit access to shared memory.
+ */
+#define WE_DELAY(wsc) delay(3)
+
+/*
+ * Enable card RAM, and 16-bit access.
+ */
+#define WE_MEM_ENABLE(wsc) \
+do { \
+ if ((wsc)->sc_16bitp) \
+ bus_space_write_1((wsc)->sc_asict, (wsc)->sc_asich, \
+ WE_LAAR, (wsc)->sc_laar_proto | WE_LAAR_M16EN); \
+ bus_space_write_1((wsc)->sc_asict, (wsc)->sc_asich, \
+ WE_MSR, wsc->sc_msr_proto | WE_MSR_MENB); \
+ WE_DELAY((wsc)); \
+} while (0)
+
+/*
+ * Disable card RAM, and 16-bit access.
+ */
+#define WE_MEM_DISABLE(wsc) \
+do { \
+ bus_space_write_1((wsc)->sc_asict, (wsc)->sc_asich, \
+ WE_MSR, (wsc)->sc_msr_proto); \
+ if ((wsc)->sc_16bitp) \
+ bus_space_write_1((wsc)->sc_asict, (wsc)->sc_asich, \
+ WE_LAAR, (wsc)->sc_laar_proto); \
+ WE_DELAY((wsc)); \
+} while (0)
+
+int
+we_config(self, wsc, typestr)
+ struct device *self;
+ struct we_softc *wsc;
+ const char *typestr;
+{
+ struct dp8390_softc *sc = &wsc->sc_dp8390;
+ u_int8_t x;
+ int i, forced_16bit = 0;
+
+ /*
+ * Allow user to override 16-bit mode. 8-bit takes precedence.
+ */
+ if (self->dv_cfdata->cf_flags & WE_FLAGS_FORCE_16BIT_MODE) {
+ wsc->sc_16bitp = 1;
+ forced_16bit = 1;
+ }
+ if (self->dv_cfdata->cf_flags & WE_FLAGS_FORCE_8BIT_MODE)
+ wsc->sc_16bitp = 0;
+
+ /* Registers are linear. */
+ for (i = 0; i < 16; i++)
+ sc->sc_reg_map[i] = i;
+
+ /* Now we can use the NIC_{GET,PUT}() macros. */
+
+ printf("%s: %s Ethernet (%s-bit)\n", sc->sc_dev.dv_xname,
+ typestr, wsc->sc_16bitp ? "16" : "8");
+
+ /* Get station address from EEPROM. */
+ for (i = 0; i < ETHER_ADDR_LEN; i++)
+ sc->sc_enaddr[i] = bus_space_read_1(wsc->sc_asict,
+ wsc->sc_asich, WE_PROM + i);
+
+ /*
+ * Set upper address bits and 8/16 bit access to shared memory.
+ */
+ if (sc->is790) {
+ wsc->sc_laar_proto =
+ bus_space_read_1(wsc->sc_asict, wsc->sc_asich, WE_LAAR) &
+ ~WE_LAAR_M16EN;
+ bus_space_write_1(wsc->sc_asict, wsc->sc_asich, WE_LAAR,
+ wsc->sc_laar_proto | (wsc->sc_16bitp ? WE_LAAR_M16EN : 0));
+ } else if ((wsc->sc_type & WE_SOFTCONFIG) ||
+#ifdef TOSH_ETHER
+ (wsc->sc_type == WE_TYPE_TOSHIBA1) ||
+ (wsc->sc_type == WE_TYPE_TOSHIBA4) ||
+#endif
+ (forced_16bit) ||
+ (wsc->sc_type == WE_TYPE_WD8013EBT)) {
+ wsc->sc_laar_proto = (wsc->sc_maddr >> 19) & WE_LAAR_ADDRHI;
+ if (wsc->sc_16bitp)
+ wsc->sc_laar_proto |= WE_LAAR_L16EN;
+ bus_space_write_1(wsc->sc_asict, wsc->sc_asich, WE_LAAR,
+ wsc->sc_laar_proto | (wsc->sc_16bitp ? WE_LAAR_M16EN : 0));
+ }
+
+ /*
+ * Set address and enable interface shared memory.
+ */
+ if (sc->is790) {
+ /* XXX MAGIC CONSTANTS XXX */
+ x = bus_space_read_1(wsc->sc_asict, wsc->sc_asich, 0x04);
+ bus_space_write_1(wsc->sc_asict, wsc->sc_asich, 0x04, x | 0x80);
+ bus_space_write_1(wsc->sc_asict, wsc->sc_asich, 0x0b,
+ ((wsc->sc_maddr >> 13) & 0x0f) |
+ ((wsc->sc_maddr >> 11) & 0x40) |
+ (bus_space_read_1(wsc->sc_asict, wsc->sc_asich, 0x0b) & 0xb0));
+ bus_space_write_1(wsc->sc_asict, wsc->sc_asich, 0x04, x);
+ wsc->sc_msr_proto = 0x00;
+ sc->cr_proto = 0x00;
+ } else {
+#ifdef TOSH_ETHER
+ if (wsc->sc_type == WE_TYPE_TOSHIBA1 ||
+ wsc->sc_type == WE_TYPE_TOSHIBA4) {
+ bus_space_write_1(wsc->sc_asict, wsc->sc_asich,
+ WE_MSR + 1,
+ ((wsc->sc_maddr >> 8) & 0xe0) | 0x04);
+ bus_space_write_1(wsc->sc_asict, wsc->sc_asich,
+ WE_MSR + 2,
+ ((wsc->sc_maddr >> 16) & 0x0f));
+ wsc->sc_msr_proto = WE_MSR_POW;
+ } else
+#endif
+ wsc->sc_msr_proto = (wsc->sc_maddr >> 13) &
+ WE_MSR_ADDR;
+
+ sc->cr_proto = ED_CR_RD2;
+ }
+
+ bus_space_write_1(wsc->sc_asict, wsc->sc_asich, WE_MSR,
+ wsc->sc_msr_proto | WE_MSR_MENB);
+ WE_DELAY(wsc);
+
+ /*
+ * DCR gets:
+ *
+ * FIFO threshold to 8, No auto-init Remote DMA,
+ * byte order=80x86.
+ *
+ * 16-bit cards also get word-wide DMA transfers.
+ */
+ sc->dcr_reg = ED_DCR_FT1 | ED_DCR_LS |
+ (wsc->sc_16bitp ? ED_DCR_WTS : 0);
+
+ sc->test_mem = we_test_mem;
+ sc->ring_copy = we_ring_copy;
+ sc->write_mbuf = we_write_mbuf;
+ sc->read_hdr = we_read_hdr;
+ sc->recv_int = we_recv_int;
+ sc->init_card = we_init_card;
+
+ sc->sc_mediachange = we_mediachange;
+ sc->sc_mediastatus = we_mediastatus;
+
+ sc->mem_start = 0;
+ /* sc->mem_size has to be set by frontend */
+
+ sc->sc_flags = self->dv_cfdata->cf_flags;
+
+ /* Do generic parts of attach. */
+ if (wsc->sc_type & WE_SOFTCONFIG)
+ sc->sc_media_init = we_media_init;
+ else
+ sc->sc_media_init = dp8390_media_init;
+ if (dp8390_config(sc)) {
+ printf("%s: configuration failed\n", sc->sc_dev.dv_xname);
+ return (1);
+ }
+
+ /*
+ * Disable 16-bit access to shared memory - we leave it disabled
+ * so that:
+ *
+ * (1) machines reboot properly when the board is set to
+ * 16-bit mode and there are conflicting 8-bit devices
+ * within the same 128k address space as this board's
Home |
Main Index |
Thread Index |
Old Index