Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Commit files for the LAN Media Corporation high ...



details:   https://anonhg.NetBSD.org/src/rev/32614fc20e61
branches:  trunk
changeset: 467461:32614fc20e61
user:      explorer <explorer%NetBSD.org@localhost>
date:      Thu Mar 25 03:32:43 1999 +0000

description:
Commit files for the LAN Media Corporation high speed serial/HSSI/DS3 driver

diffstat:

 sys/dev/pci/if_lmc.c        |  1370 +++++++++++++++++++++++++++++++++++++++++++
 sys/dev/pci/if_lmc_common.c |   398 ++++++++++++
 sys/dev/pci/if_lmc_media.c  |   793 ++++++++++++++++++++++++
 sys/dev/pci/if_lmc_nbsd.c   |   380 +++++++++++
 sys/dev/pci/if_lmc_types.h  |    66 ++
 sys/dev/pci/if_lmcioctl.h   |   256 ++++++++
 sys/dev/pci/if_lmcvar.h     |   606 +++++++++++++++++++
 7 files changed, 3869 insertions(+), 0 deletions(-)

diffs (truncated from 3897 to 300 lines):

diff -r 57f9b0addd1d -r 32614fc20e61 sys/dev/pci/if_lmc.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/if_lmc.c      Thu Mar 25 03:32:43 1999 +0000
@@ -0,0 +1,1370 @@
+/*     $NetBSD: if_lmc.c,v 1.1 1999/03/25 03:32:43 explorer Exp $      */
+
+/*-
+ * Copyright (c) 1997-1999 LAN Media Corporation (LMC)
+ * All rights reserved.  www.lanmedia.com
+ *
+ * This code is written by Michael Graff <graff%vix.com@localhost> for LMC.
+ * The code is derived from permitted modifications to software created
+ * by Matt Thomas (matt%3am-software.com@localhost).
+ *
+ * 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 marketing or advertising materials mentioning features or
+ *    use of this software must display the following acknowledgement:
+ *      This product includes software developed by LAN Media Corporation
+ *      and its contributors.
+ * 4. Neither the name of LAN Media Corporation 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 LAN MEDIA CORPORATION 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-1997 Matt Thomas (matt%3am-software.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. The name of the author may not be used to endorse or promote products
+ *    derived from this software withough specific prior written permission
+ *
+ * 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.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/errno.h>
+#include <sys/malloc.h>
+#include <sys/kernel.h>
+#include <sys/proc.h>  /* only for declaration of wakeup() used by vm.h */
+#if defined(__FreeBSD__)
+#include <machine/clock.h>
+#elif defined(__bsdi__) || defined(__NetBSD__)
+#include <sys/device.h>
+#endif
+
+#if defined(__NetBSD__)
+#include <dev/pci/pcidevs.h>
+#include "rnd.h"
+#if NRND > 0
+#include <sys/rnd.h>
+#endif
+#endif
+
+#include <net/if.h>
+#include <net/if_types.h>
+#include <net/if_dl.h>
+#include <net/netisr.h>
+
+#include "bpfilter.h"
+#if NBPFILTER > 0
+#include <net/bpf.h>
+#include <net/bpfdesc.h>
+#endif
+
+#include <vm/vm.h>
+#include <vm/vm_param.h>
+#include <vm/vm_kern.h>
+
+#if defined(__FreeBSD__) || defined(__NetBSD__)
+#include <net/if_sppp.h>
+#endif
+
+#if defined(__bsdi__)
+#if INET
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/ip.h>
+#endif
+
+#include <net/netisr.h>
+#include <net/if.h>
+#include <net/netisr.h>
+#include <net/if_types.h>
+#include <net/if_p2p.h>
+#include <net/if_c_hdlc.h>
+#endif
+
+#if defined(__FreeBSD__)
+#include <vm/pmap.h>
+#include <pci.h>
+#if NPCI > 0
+#include <pci/pcivar.h>
+#include <pci/dc21040reg.h>
+#define INCLUDE_PATH_PREFIX "pci/"
+#endif
+#endif /* __FreeBSD__ */
+
+#if defined(__bsdi__)
+#include <i386/pci/ic/dc21040.h>
+#include <i386/isa/isa.h>
+#include <i386/isa/icu.h>
+#include <i386/isa/dma.h>
+#include <i386/isa/isavar.h>
+#include <i386/pci/pci.h>
+
+#define        INCLUDE_PATH_PREFIX     "i386/pci/"
+#endif /* __bsdi__ */
+
+#if defined(__NetBSD__)
+#include <machine/bus.h>
+#if defined(__alpha__)
+#include <machine/intr.h>
+#endif
+#include <dev/pci/pcireg.h>
+#include <dev/pci/pcivar.h>
+#include <dev/ic/dc21040reg.h>
+#define        INCLUDE_PATH_PREFIX     "dev/pci/"
+#endif /* __NetBSD__ */
+
+/*
+ * Sigh.  Every OS puts these in different places.  NetBSD and FreeBSD use
+ * a C preprocessor that allows this hack, but BSDI does not.  Grr.
+ */
+#if defined(__NetBSD__) || defined(__FreeBSD__)
+#include INCLUDE_PATH_PREFIX "if_lmc_types.h"
+#include INCLUDE_PATH_PREFIX "if_lmcioctl.h"
+#include INCLUDE_PATH_PREFIX "if_lmcvar.h"
+#else /* BSDI */
+#include "i386/pci/if_lmctypes.h"
+#include "i386/pci/if_lmcioctl.h"
+#include "i386/pci/if_lmcvar.h"
+#endif
+
+/*
+ * This module supports
+ *     the DEC 21140A pass 2.2 PCI Fast Ethernet Controller.
+ */
+static ifnet_ret_t lmc_ifstart_one(struct ifnet *ifp);
+static ifnet_ret_t lmc_ifstart(struct ifnet *ifp);
+static struct mbuf *lmc_txput(lmc_softc_t * const sc, struct mbuf *m);
+static void lmc_rx_intr(lmc_softc_t * const sc);
+
+#if defined(__NetBSD__) || defined(__FreeBSD__)
+static void lmc_watchdog(struct ifnet *ifp);
+#endif
+#if defined(__bsdi__)
+static int lmc_watchdog(int);
+#endif
+static void lmc_ifup(lmc_softc_t * const sc);
+static void lmc_ifdown(lmc_softc_t * const sc);
+
+
+/*
+ * Code the read the SROM and MII bit streams (I2C)
+ */
+static inline void
+lmc_delay_300ns(lmc_softc_t * const sc)
+{
+       int idx;
+       for (idx = (300 / 33) + 1; idx > 0; idx--)
+               (void)LMC_CSR_READ(sc, csr_busmode);
+}
+
+
+#define EMIT    \
+do { \
+       LMC_CSR_WRITE(sc, csr_srom_mii, csr); \
+       lmc_delay_300ns(sc); \
+} while (0)
+
+static inline void
+lmc_srom_idle(lmc_softc_t * const sc)
+{
+       unsigned bit, csr;
+    
+       csr  = SROMSEL ; EMIT;
+       csr  = SROMSEL | SROMRD; EMIT;  
+       csr ^= SROMCS; EMIT;
+       csr ^= SROMCLKON; EMIT;
+
+       /*
+        * Write 25 cycles of 0 which will force the SROM to be idle.
+        */
+       for (bit = 3 + SROM_BITWIDTH + 16; bit > 0; bit--) {
+               csr ^= SROMCLKOFF; EMIT;    /* clock low; data not valid */
+               csr ^= SROMCLKON; EMIT;     /* clock high; data valid */
+       }
+       csr ^= SROMCLKOFF; EMIT;
+       csr ^= SROMCS; EMIT;
+       csr  = 0; EMIT;
+}
+
+     
+static void
+lmc_srom_read(lmc_softc_t * const sc)
+{   
+       unsigned idx; 
+       const unsigned bitwidth = SROM_BITWIDTH;
+       const unsigned cmdmask = (SROMCMD_RD << bitwidth);
+       const unsigned msb = 1 << (bitwidth + 3 - 1);
+       unsigned lastidx = (1 << bitwidth) - 1;
+
+       lmc_srom_idle(sc);
+
+       for (idx = 0; idx <= lastidx; idx++) {
+               unsigned lastbit, data, bits, bit, csr;
+               csr  = SROMSEL ;                EMIT;
+               csr  = SROMSEL | SROMRD;        EMIT;
+               csr ^= SROMCSON;                EMIT;
+               csr ^=            SROMCLKON;    EMIT;
+    
+               lastbit = 0;
+               for (bits = idx|cmdmask, bit = bitwidth + 3
+                            ; bit > 0
+                            ; bit--, bits <<= 1) {
+                       const unsigned thisbit = bits & msb;
+                       csr ^= SROMCLKOFF; EMIT;    /* clock L data invalid */
+                       if (thisbit != lastbit) {
+                               csr ^= SROMDOUT; EMIT;/* clock L invert data */
+                       } else {
+                               EMIT;
+                       }
+                       csr ^= SROMCLKON; EMIT;     /* clock H data valid */
+                       lastbit = thisbit;
+               }
+               csr ^= SROMCLKOFF; EMIT;
+
+               for (data = 0, bits = 0; bits < 16; bits++) {
+                       data <<= 1;
+                       csr ^= SROMCLKON; EMIT;     /* clock H data valid */ 
+                       data |= LMC_CSR_READ(sc, csr_srom_mii) & SROMDIN ? 1 : 0;
+                       csr ^= SROMCLKOFF; EMIT;    /* clock L data invalid */
+               }
+               sc->lmc_rombuf[idx*2] = data & 0xFF;
+               sc->lmc_rombuf[idx*2+1] = data >> 8;
+               csr  = SROMSEL | SROMRD; EMIT;
+               csr  = 0; EMIT;
+       }
+       lmc_srom_idle(sc);
+}
+
+#define MII_EMIT    do { LMC_CSR_WRITE(sc, csr_srom_mii, csr); lmc_delay_300ns(sc); } while (0)
+
+static inline void
+lmc_mii_writebits(lmc_softc_t * const sc, unsigned data, unsigned bits)
+{
+    unsigned msb = 1 << (bits - 1);
+    unsigned csr = LMC_CSR_READ(sc, csr_srom_mii) & (MII_RD|MII_DOUT|MII_CLK);
+    unsigned lastbit = (csr & MII_DOUT) ? msb : 0;
+
+    csr |= MII_WR; MII_EMIT;           /* clock low; assert write */
+
+    for (; bits > 0; bits--, data <<= 1) {
+       const unsigned thisbit = data & msb;
+       if (thisbit != lastbit) {
+           csr ^= MII_DOUT; MII_EMIT;  /* clock low; invert data */
+       }
+       csr ^= MII_CLKON; MII_EMIT;     /* clock high; data valid */
+       lastbit = thisbit;
+       csr ^= MII_CLKOFF; MII_EMIT;    /* clock low; data not valid */
+    }
+}



Home | Main Index | Thread Index | Old Index