Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Driver for Broadcom 570x / Altima AC 1000 gigabi...



details:   https://anonhg.NetBSD.org/src/rev/6cfa9e6688c0
branches:  trunk
changeset: 533147:6cfa9e6688c0
user:      fvdl <fvdl%NetBSD.org@localhost>
date:      Sat Jun 22 14:42:07 2002 +0000

description:
Driver for Broadcom 570x / Altima AC 1000 gigabit ethernet cards.
Written by Bill Paul for FreeBSD. This port started out with the
port done to OpenBSD by nate%openbsd.org@localhost, but ended up looking much
more like the port of the ti driver done by drochner%netbsd.org@localhost
(they are similar in structure).

diffstat:

 sys/dev/pci/if_bge.c    |  2855 +++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/pci/if_bgereg.h |  2262 +++++++++++++++++++++++++++++++++++++
 2 files changed, 5117 insertions(+), 0 deletions(-)

diffs (truncated from 5125 to 300 lines):

diff -r bcae14b002a0 -r 6cfa9e6688c0 sys/dev/pci/if_bge.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/if_bge.c      Sat Jun 22 14:42:07 2002 +0000
@@ -0,0 +1,2855 @@
+/*     $NetBSD: if_bge.c,v 1.1 2002/06/22 14:42:07 fvdl Exp $  */
+/*
+ * Copyright (c) 2001 Wind River Systems
+ * Copyright (c) 1997, 1998, 1999, 2001
+ *     Bill Paul <wpaul%windriver.com@localhost>.  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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by Bill Paul.
+ * 4. Neither the name of the author nor the names of any co-contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Bill Paul 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 Bill Paul OR THE VOICES IN HIS HEAD
+ * 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.
+ *
+ * $FreeBSD: if_bge.c,v 1.13 2002/04/04 06:01:31 wpaul Exp $
+ */
+
+/*
+ * Broadcom BCM570x family gigabit ethernet driver for FreeBSD.
+ *
+ * Written by Bill Paul <wpaul%windriver.com@localhost>
+ * Senior Engineer, Wind River Systems
+ */
+
+/*
+ * The Broadcom BCM5700 is based on technology originally developed by
+ * Alteon Networks as part of the Tigon I and Tigon II gigabit ethernet
+ * MAC chips. The BCM5700, sometimes refered to as the Tigon III, has
+ * two on-board MIPS R4000 CPUs and can have as much as 16MB of external
+ * SSRAM. The BCM5700 supports TCP, UDP and IP checksum offload, jumbo
+ * frames, highly configurable RX filtering, and 16 RX and TX queues
+ * (which, along with RX filter rules, can be used for QOS applications).
+ * Other features, such as TCP segmentation, may be available as part
+ * of value-added firmware updates. Unlike the Tigon I and Tigon II,
+ * firmware images can be stored in hardware and need not be compiled
+ * into the driver.
+ *
+ * The BCM5700 supports the PCI v2.2 and PCI-X v1.0 standards, and will
+ * function in a 32-bit/64-bit 33/66Mhz bus, or a 64-bit/133Mhz bus.
+ *
+ * The BCM5701 is a single-chip solution incorporating both the BCM5700
+ * MAC and a BCM5401 10/100/1000 PHY. Unlike the BCM5700, the BCM5700
+ * does not support external SSRAM.
+ *
+ * Broadcom also produces a variation of the BCM5700 under the "Altima"
+ * brand name, which is functionally similar but lacks PCI-X support.
+ *
+ * Without external SSRAM, you can only have at most 4 TX rings,
+ * and the use of the mini RX ring is disabled. This seems to imply
+ * that these features are simply not available on the BCM5701. As a
+ * result, this driver does not implement any support for the mini RX
+ * ring.
+ */
+
+#include "bpfilter.h"
+#include "vlan.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/callout.h>
+#include <sys/sockio.h>
+#include <sys/mbuf.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/socket.h>
+
+#include <net/if.h>
+#include <net/if_dl.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>
+#endif
+
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#endif
+
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/pcidevs.h>
+
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+#include <dev/mii/miidevs.h>
+#include <dev/mii/brgphyreg.h>
+
+#include <dev/pci/if_bgereg.h>
+
+#include <uvm/uvm_extern.h>
+
+/* #define BGE_CHECKSUM */
+
+int bge_probe(struct device *, struct cfdata *, void *);
+void bge_attach(struct device *, struct device *, void *);
+void bge_release_resources(struct bge_softc *);
+void bge_txeof(struct bge_softc *);
+void bge_rxeof(struct bge_softc *);
+
+void bge_tick(void *);
+void bge_stats_update(struct bge_softc *);
+int bge_encap(struct bge_softc *, struct mbuf *, u_int32_t *);
+
+int bge_intr(void *);
+void bge_start(struct ifnet *);
+int bge_ioctl(struct ifnet *, u_long, caddr_t);
+int bge_init(struct ifnet *);
+void bge_stop(struct bge_softc *);
+void bge_watchdog(struct ifnet *);
+void bge_shutdown(void *);
+int bge_ifmedia_upd(struct ifnet *);
+void bge_ifmedia_sts(struct ifnet *, struct ifmediareq *);
+
+u_int8_t bge_eeprom_getbyte(struct bge_softc *, int, u_int8_t *);
+int bge_read_eeprom(struct bge_softc *, caddr_t, int, int);
+
+u_int32_t bge_crc(struct bge_softc *, caddr_t);
+void bge_setmulti(struct bge_softc *);
+
+void bge_handle_events(struct bge_softc *);
+int bge_alloc_jumbo_mem(struct bge_softc *);
+void bge_free_jumbo_mem(struct bge_softc *);
+void *bge_jalloc(struct bge_softc *);
+void bge_jfree(struct mbuf *, caddr_t, u_int, void *);
+int bge_newbuf_std(struct bge_softc *, int, struct mbuf *, bus_dmamap_t);
+int bge_newbuf_jumbo(struct bge_softc *, int, struct mbuf *);
+int bge_init_rx_ring_std(struct bge_softc *);
+void bge_free_rx_ring_std(struct bge_softc *);
+int bge_init_rx_ring_jumbo(struct bge_softc *);
+void bge_free_rx_ring_jumbo(struct bge_softc *);
+void bge_free_tx_ring(struct bge_softc *);
+int bge_init_tx_ring(struct bge_softc *);
+
+int bge_chipinit(struct bge_softc *);
+int bge_blockinit(struct bge_softc *);
+
+#ifdef notdef
+u_int8_t bge_vpd_readbyte(struct bge_softc *, int);
+void bge_vpd_read_res(struct bge_softc *, struct vpd_res *, int);
+void bge_vpd_read(struct bge_softc *);
+#endif
+
+u_int32_t bge_readmem_ind(struct bge_softc *, int);
+void bge_writemem_ind(struct bge_softc *, int, int);
+#ifdef notdef
+u_int32_t bge_readreg_ind(struct bge_softc *, int);
+#endif
+void bge_writereg_ind(struct bge_softc *, int, int);
+
+int bge_miibus_readreg(struct device *, int, int);
+void bge_miibus_writereg(struct device *, int, int, int);
+void bge_miibus_statchg(struct device *);
+
+void bge_reset(struct bge_softc *);
+void bge_phy_hack(struct bge_softc *);
+
+void bge_dump_status(struct bge_softc *);
+void bge_dump_rxbd(struct bge_rx_bd *);
+
+#define BGE_DEBUG
+#ifdef BGE_DEBUG
+#define DPRINTF(x)     if (bgedebug) printf x
+#define DPRINTFN(n,x)  if (bgedebug >= (n)) printf x
+int    bgedebug = 0;
+#else
+#define DPRINTF(x)
+#define DPRINTFN(n,x)
+#endif
+
+struct cfattach bge_ca = {
+       sizeof(struct bge_softc), bge_probe, bge_attach
+};
+
+u_int32_t
+bge_readmem_ind(sc, off)
+       struct bge_softc *sc;
+       int off;
+{
+       struct pci_attach_args  *pa = &(sc->bge_pa);
+       pcireg_t val;
+
+       pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_MEMWIN_BASEADDR, off);
+       val = pci_conf_read(pa->pa_pc, pa->pa_tag, BGE_PCI_MEMWIN_DATA);
+       return val;
+}
+
+void
+bge_writemem_ind(sc, off, val)
+       struct bge_softc *sc;
+       int off, val;
+{
+       struct pci_attach_args  *pa = &(sc->bge_pa);
+
+       pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_MEMWIN_BASEADDR, off);
+       pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_MEMWIN_DATA, val);
+}
+
+#ifdef notdef
+u_int32_t
+bge_readreg_ind(sc, off)
+       struct bge_softc *sc;
+       int off;
+{
+       struct pci_attach_args  *pa = &(sc->bge_pa);
+
+       pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_REG_BASEADDR, off);
+       return(pci_conf_read(pa->pa_pc, pa->pa_tag, BGE_PCI_REG_DATA));
+}
+#endif
+
+void
+bge_writereg_ind(sc, off, val)
+       struct bge_softc *sc;
+       int off, val;
+{
+       struct pci_attach_args  *pa = &(sc->bge_pa);
+
+       pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_REG_BASEADDR, off);
+       pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_REG_DATA, val);
+}
+
+#ifdef notdef
+u_int8_t
+bge_vpd_readbyte(sc, addr)
+       struct bge_softc *sc;
+       int addr;
+{
+       int i;
+       u_int32_t val;
+       struct pci_attach_args  *pa = &(sc->bge_pa);
+
+       pci_conf_write(pa->pa_pc, pa->pa_tag, BGE_PCI_VPD_ADDR, addr);
+       for (i = 0; i < BGE_TIMEOUT * 10; i++) {
+               DELAY(10);
+               if (pci_conf_read(pa->pa_pc, pa->pa_tag, BGE_PCI_VPD_ADDR) &
+                   BGE_VPD_FLAG)
+                       break;
+       }
+
+       if (i == BGE_TIMEOUT) {
+               printf("%s: VPD read timed out\n", sc->bge_dev.dv_xname);
+               return(0);
+       }
+
+       val = pci_conf_read(pa->pa_pc, pa->pa_tag, BGE_PCI_VPD_DATA);
+
+       return((val >> ((addr % 4) * 8)) & 0xFF);
+}
+
+void
+bge_vpd_read_res(sc, res, addr)
+       struct bge_softc *sc;
+       struct vpd_res *res;
+       int addr;
+{
+       int i;
+       u_int8_t *ptr;
+
+       ptr = (u_int8_t *)res;
+       for (i = 0; i < sizeof(struct vpd_res); i++)
+               ptr[i] = bge_vpd_readbyte(sc, i + addr);
+}
+
+void
+bge_vpd_read(sc)
+       struct bge_softc *sc;
+{
+       int pos = 0, i;
+       struct vpd_res res;
+
+       if (sc->bge_vpd_prodname != NULL)
+               free(sc->bge_vpd_prodname, M_DEVBUF);



Home | Main Index | Thread Index | Old Index