Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/ic Bus-independent back-end driver for Intel i82557 ...
details: https://anonhg.NetBSD.org/src/rev/0e256d90ff79
branches: trunk
changeset: 473874:0e256d90ff79
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sun Jun 20 16:33:28 1999 +0000
description:
Bus-independent back-end driver for Intel i82557 fast Ethernet chips.
diffstat:
sys/dev/ic/i82557.c | 1668 ++++++++++++++++++++++++++++++++++++++++++++++++
sys/dev/ic/i82557reg.h | 398 +++++++++++
sys/dev/ic/i82557var.h | 199 +++++
3 files changed, 2265 insertions(+), 0 deletions(-)
diffs (truncated from 2277 to 300 lines):
diff -r d96eb949446c -r 0e256d90ff79 sys/dev/ic/i82557.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/ic/i82557.c Sun Jun 20 16:33:28 1999 +0000
@@ -0,0 +1,1668 @@
+/* $NetBSD: i82557.c,v 1.1 1999/06/20 16:33:28 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 1997, 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.
+ */
+
+/*
+ * Copyright (c) 1995, David Greenman
+ * 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 unmodified, 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 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 AUTHOR 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.
+ *
+ * Id: if_fxp.c,v 1.47 1998/01/08 23:42:29 eivind Exp
+ */
+
+/*
+ * Device driver for the Intel i82557 fast Ethernet controller.
+ */
+
+#include "opt_inet.h"
+#include "opt_ns.h"
+#include "bpfilter.h"
+#include "rnd.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 */
+
+#if NRND > 0
+#include <sys/rnd.h>
+#endif
+
+#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/miivar.h>
+
+#include <dev/ic/i82557reg.h>
+#include <dev/ic/i82557var.h>
+
+/*
+ * NOTE! On the Alpha, we have an alignment constraint. The
+ * card DMAs the packet immediately following the RFA. However,
+ * the first thing in the packet is a 14-byte Ethernet header.
+ * This means that the packet is misaligned. To compensate,
+ * we actually offset the RFA 2 bytes into the cluster. This
+ * alignes the packet after the Ethernet header at a 32-bit
+ * boundary. HOWEVER! This means that the RFA is misaligned!
+ */
+#define RFA_ALIGNMENT_FUDGE 2
+
+/*
+ * Template for default configuration parameters.
+ * See struct fxp_cb_config for the bit definitions.
+ */
+u_int8_t fxp_cb_config_template[] = {
+ 0x0, 0x0, /* cb_status */
+ 0x80, 0x2, /* cb_command */
+ 0xff, 0xff, 0xff, 0xff, /* link_addr */
+ 0x16, /* 0 */
+ 0x8, /* 1 */
+ 0x0, /* 2 */
+ 0x0, /* 3 */
+ 0x0, /* 4 */
+ 0x80, /* 5 */
+ 0xb2, /* 6 */
+ 0x3, /* 7 */
+ 0x1, /* 8 */
+ 0x0, /* 9 */
+ 0x26, /* 10 */
+ 0x0, /* 11 */
+ 0x60, /* 12 */
+ 0x0, /* 13 */
+ 0xf2, /* 14 */
+ 0x48, /* 15 */
+ 0x0, /* 16 */
+ 0x40, /* 17 */
+ 0xf3, /* 18 */
+ 0x0, /* 19 */
+ 0x3f, /* 20 */
+ 0x5 /* 21 */
+};
+
+void fxp_mii_initmedia __P((struct fxp_softc *));
+int fxp_mii_mediachange __P((struct ifnet *));
+void fxp_mii_mediastatus __P((struct ifnet *, struct ifmediareq *));
+
+void fxp_80c24_initmedia __P((struct fxp_softc *));
+int fxp_80c24_mediachange __P((struct ifnet *));
+void fxp_80c24_mediastatus __P((struct ifnet *, struct ifmediareq *));
+
+inline void fxp_scb_wait __P((struct fxp_softc *));
+
+void fxp_start __P((struct ifnet *));
+int fxp_ioctl __P((struct ifnet *, u_long, caddr_t));
+void fxp_init __P((void *));
+void fxp_stop __P((struct fxp_softc *));
+void fxp_watchdog __P((struct ifnet *));
+int fxp_add_rfabuf __P((struct fxp_softc *, struct fxp_rxdesc *));
+int fxp_mdi_read __P((struct device *, int, int));
+void fxp_statchg __P((struct device *));
+void fxp_mdi_write __P((struct device *, int, int, int));
+void fxp_read_eeprom __P((struct fxp_softc *, u_int16_t *, int, int));
+void fxp_get_info __P((struct fxp_softc *, u_int8_t *));
+void fxp_tick __P((void *));
+void fxp_mc_setup __P((struct fxp_softc *));
+
+void fxp_shutdown __P((void *));
+
+struct fxp_phytype {
+ int fp_phy; /* type of PHY, -1 for MII at the end. */
+ void (*fp_init) __P((struct fxp_softc *));
+} fxp_phytype_table[] = {
+ { FXP_PHY_80C24, fxp_80c24_initmedia },
+ { -1, fxp_mii_initmedia },
+};
+
+/*
+ * Set initial transmit threshold at 64 (512 bytes). This is
+ * increased by 64 (512 bytes) at a time, to maximum of 192
+ * (1536 bytes), if an underrun occurs.
+ */
+static int tx_threshold = 64;
+
+/*
+ * Wait for the previous command to be accepted (but not necessarily
+ * completed).
+ */
+inline void
+fxp_scb_wait(sc)
+ struct fxp_softc *sc;
+{
+ int i = 10000;
+
+ while (CSR_READ_1(sc, FXP_CSR_SCB_COMMAND) && --i)
+ DELAY(1);
+ if (i == 0)
+ printf("%s: WARNING: SCB timed out!\n", sc->sc_dev.dv_xname);
+}
+
+/*
+ * Finish attaching an i82557 interface. Called by bus-specific front-end.
+ */
+void
+fxp_attach(sc)
+ struct fxp_softc *sc;
+{
+ u_int8_t enaddr[6];
+ struct ifnet *ifp;
+ bus_dma_segment_t seg;
+ int rseg, i, error;
+ struct fxp_phytype *fp;
+
+ /*
+ * Allocate the control data structures, and create and load the
+ * DMA map for it.
+ */
+ if ((error = bus_dmamem_alloc(sc->sc_dmat,
+ sizeof(struct fxp_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 fxp_control_data), (caddr_t *)&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;
+ }
+ bzero(sc->control_data, sizeof(struct fxp_control_data));
+
+ if ((error = bus_dmamap_create(sc->sc_dmat,
+ sizeof(struct fxp_control_data), 1,
+ sizeof(struct fxp_control_data), 0, 0, &sc->sc_dmamap)) != 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_dmamap,
+ sc->control_data, sizeof(struct fxp_control_data), NULL,
+ 0)) != 0) {
+ printf("%s: can't 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 < FXP_NTXCB; i++) {
+ if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES,
+ FXP_NTXSEG, MCLBYTES, 0, 0,
+ &sc->sc_tx_dmamaps[i])) != 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 receive buffer DMA maps.
+ */
+ for (i = 0; i < FXP_NRFABUFS; i++) {
+ if ((error = bus_dmamap_create(sc->sc_dmat, MCLBYTES, 1,
+ MCLBYTES, 0, 0, &sc->sc_rx_dmamaps[i])) != 0) {
+ printf("%s: unable to create rx DMA map %d, "
+ "error = %d\n", sc->sc_dev.dv_xname, i, error);
+ goto fail_5;
+ }
+ }
+
+ /*
Home |
Main Index |
Thread Index |
Old Index